"""
constants_v2.py - 配置项统一管理
文档保存目录：/e:/DEV_VISION/backend/config/constants_v2.py

文件功能：统一管理系统所有配置项，支持动态加载和验证
适用范围：DEV_VISION项目所有模块的配置管理
强制性质：本文件为强制执行标准，所有配置项必须在此定义
"""

import json
import os

# ==================== 全局通用选项池（GLOBAL_OPTIONS_CONFIG） ====================
GLOBAL_OPTIONS_CONFIG = {
    # === 基础信息选项 ===
    "school_options": [
        "苏宁红军小学", "华兴小学", "师大附小清华小学", "红岩小学"
    ],
    "class_options": [
        "1班", "2班", "3班", "4班", "5班", "6班", "7班", "8班", "9班", "10班", "11班", "12班", "13班", "14班", "15班"
    ],
    "grade_options": [
        "一年级", "二年级", "三年级", "四年级", "五年级", "六年级", 
    ],
    # 性别选项（扩展：增加“其他”，保持原有顺序与兼容性，向后新增不破坏旧依赖）
    "gender_options": ["男", "女", "其他"],
    "data_year_options": [str(y) for y in range(2023, 2031)],
    
    # === 健康信息选项 ===
    "premature_options": ["是", "否", "不详"],
    "diet_preference_options": ["清淡", "均衡", "偏重口味"],
    "exercise_preference_options": ["无", "每周1-2次", "每周3-4次", "每周5次及以上"],
    "health_education_options": ["无", "每周1次", "每周2次", "每周3次及以上"],
    "past_history_options": ["无", "有"],
    "family_history_options": ["无", "有"],
    "allergy_options": ["无", "有"],
    
    # === 矫正方式选项 ===
    "correction_method_options": [
        "框架眼镜", "隐形眼镜", "夜戴角膜塑形镜", "无矫正", "其它"
    ],
    "frame_glasses_options": ["是", "否"],
    "contact_lenses_options": ["是", "否"],
    "night_orthokeratology_options": ["是", "否"],
    
    # === 视力等级选项 ===
    "vision_level_options": [
        "假性近视",      # 散瞳后SE=0，最高优先级
        "高度近视",      # SE < -6.00D
        "中度近视",      # -6.00D ≤ SE < -3.00D
        "轻度近视",      # -3.00D ≤ SE < -0.5D
        "正常视力",      # -0.5D ≤ SE ≤ +0.5D
        "临床前期近视",   # 年龄分层判定
        "远视"          # SE > +0.5D且≥13岁
    ],
    "myopia_degree_options": ["轻度近视", "中度近视", "高度近视"],
    
    # === 视力检查选项 ===
    "measure_type_options": [
        "常规检查", "复查", "干预后检查", "年度体检", "专项检查", "筛查"
    ],
    "measure_location_options": [
        "曲线社区卫生服务中心", "学校医务室", "区县医院", "市级医院", "专科医院", "其他"
    ],
    "eye_fatigue_options": [
        "无", "偶尔", "经常", "严重"
    ],
    "is_baseline_options": ["是", "否"],
    
    # === 干预相关选项 ===
    "intervention_type_options": ["耳穴压丸", "刮痧", "艾灸", "中药熏蒸", "热灸训练", "热磁脉冲", "拔罐"],
    "intervention_effect_options": ["上升", "维持", "下降"],
    "operation_location_options": ["门诊一楼", "门诊二楼", "门诊三楼", "住院部", "中医科", "眼科", "儿科", "家庭", "学校", "其他"],
    
    # === 随访相关选项 ===
    "followup_type_options": ["常规随访", "专项随访", "紧急随访", "满意度调查"],
    "interviewee_relation_options": [
        "父亲", "母亲", "祖父母", "外祖父母", "其他亲属", "本人", "其他"
    ],
    "contact_method_options": [
        "电话", "微信", "QQ", "短信", "当面", "其他"
    ],
    "intervention_satisfaction_options": [
        "非常满意", "满意", "一般", "不满意"
    ],
    "intervention_effect_evaluation_options": [
        "明显改善", "有改善", "无变化", "加重"
    ],
    "intervention_compliance_options": [
        "完全依从", "部分依从", "不依从"
    ],
    "vision_change_perception_options": [
        "明显好转", "略有好转", "无变化", "变差"
    ]
}

# ==================== 全局通用选项池结束 ====================

# ==================== 全局唯一字段配置表（嵌套结构） ====================
# 以数据模型为唯一标准，紧凑定义所有主表及日志表字段属性，便于全局复用
ALL_FIELD_CONFIG_REGISTRY = {
    # Alembic 数据库迁移表
    "alembic_version": {
        "version_num": {"type": "string", "display_name": "版本号"}
    },
    
    "students": {
        "id": {"type": "int", "display_name": "学生ID"},
        "education_id": {"type": "string", "display_name": "教育ID号", "required": True, "unique": True, "width": 100},
        "school": {"type": "string", "display_name": "学校", "input_type": "select", "options_source": "school_options", },
        "class_name": {"type": "string", "display_name": "班级", "input_type": "select", "options_source": "class_options", "width": 100},
        "name": {"type": "string", "display_name": "姓名", "required": True, "max_length": 50, "width": 100},
        "gender": {"type": "string", "display_name": "性别", "input_type": "select", "options_source": "gender_options", "width": 80},
        "birthday": {"type": "date", "display_name": "出生日期"},
        "phone": {"type": "string", "display_name": "联系电话", "max_length": 15},
        "id_card": {"type": "string", "display_name": "身份证号码", "max_length": 18},
        "region": {"type": "string", "display_name": "区域", "max_length": 50},
        "contact_address": {"type": "string", "display_name": "联系地址", "max_length": 100},
        "parent_name": {"type": "string", "display_name": "家长姓名", "max_length": 50},
        "parent_phone": {"type": "string", "display_name": "家长电话", "max_length": 15},
    },
    "student_extensions": {
        "id": {"type": "int", "display_name": "扩展ID"},
        "student_id": {"type": "int", "display_name": "学生ID", "required": True},
        "data_year": {"type": "string", "display_name": "数据年份", "input_type": "select", "options_source": "data_year_options", "width": 100},
        "grade": {"type": "string", "display_name": "年级", "input_type": "select", "options_source": "grade_options", "width": 100},
        "age": {"type": "int", "display_name": "年龄", "width": 80},
        "height": {"type": "float", "display_name": "身高"},
        "weight": {"type": "float", "display_name": "体重"},
        "diet_preference": {"type": "string", "display_name": "饮食偏好", "input_type": "select", "options_source": "diet_preference_options", "max_length": 50},
        "exercise_preference": {"type": "string", "display_name": "运动偏好", "input_type": "select", "options_source": "exercise_preference_options", "max_length": 50},
        "health_education": {"type": "string", "display_name": "健康教育", "input_type": "select", "options_source": "health_education_options", "max_length": 200},
        "past_history": {"type": "string", "display_name": "既往史", "input_type": "select", "options_source": "past_history_options", "max_length": 200},
        "family_history": {"type": "string", "display_name": "家族史", "input_type": "select", "options_source": "family_history_options", "max_length": 200},
        "premature": {"type": "string", "display_name": "是否早产", "input_type": "select", "options_source": "premature_options", "max_length": 10},
        "allergy": {"type": "string", "display_name": "过敏史", "input_type": "select", "options_source": "allergy_options", "max_length": 200},
        "correction_method": {"type": "string", "display_name": "矫正方式", "input_type": "select", "options_source": "correction_method_options", "max_length": 100},
        "frame_glasses": {"type": "bool", "display_name": "框架眼镜", "input_type": "select", "options_source": "frame_glasses_options", "default": False},
        "contact_lenses": {"type": "bool", "display_name": "隐形眼镜", "input_type": "select", "options_source": "contact_lenses_options", "default": False},
        "night_orthokeratology": {"type": "bool", "display_name": "夜戴角膜塑形镜", "input_type": "select", "options_source": "night_orthokeratology_options", "default": False}
    },
    "vision_records": {
        "id": {"type": "int", "display_name": "记录ID"},
        "student_id": {"type": "int", "display_name": "学生ID", "required": True},
        "measure_date": {"type": "date", "display_name": "测量日期", "required": True},
        "measure_time": {"type": "time", "display_name": "测量时间"},
        "measure_location": {"type": "string", "display_name": "检查地点", "max_length": 100, "input_type": "select", "options_source": "measure_location_options"},
        "measure_type": {"type": "string", "display_name": "检查类型", "max_length": 20, "default": "常规检查", "input_type": "select", "options_source": "measure_type_options"},
        "measurer": {"type": "string", "display_name": "检查人员", "max_length": 50},
        "is_baseline": {"type": "bool", "display_name": "是否基线", "default": False},
        "measurement_sequence": {"type": "int", "display_name": "测量序号"},
        "age_at_measure": {"type": "int", "display_name": "测量时年龄"},
        "data_year": {"type": "string", "display_name": "数据年份", "max_length": 4},
        "is_baseline": {"type": "bool", "display_name": "是否基线", "input_type": "select", "options_source": "is_baseline_options", "default": False},
        "left_eye_naked": {"type": "float", "supports_range": "true", "display_name": "左眼裸眼视力"},
        "right_eye_naked": {"type": "float", "supports_range": "true", "display_name": "右眼裸眼视力"},
        "left_eye_corrected": {"type": "float", "supports_range": "true", "display_name": "左眼矫正视力"},
        "right_eye_corrected": {"type": "float", "supports_range": "true", "display_name": "右眼矫正视力"},
        "left_sphere": {"type": "float", "supports_range": "true", "display_name": "左眼球镜"},
        "right_sphere": {"type": "float", "supports_range": "true", "display_name": "右眼球镜"},
        "left_cylinder": {"type": "float", "supports_range": "true", "display_name": "左眼柱镜"},
        "right_cylinder": {"type": "float", "supports_range": "true", "display_name": "右眼柱镜"},
        "left_axis": {"type": "float", "supports_range": "true", "display_name": "左眼轴位"},
        "right_axis": {"type": "float", "supports_range": "true", "display_name": "右眼轴位"},
        "left_se": {"type": "float", "supports_range": "true", "display_name": "左眼等效球镜度"},
        "right_se": {"type": "float", "supports_range": "true", "display_name": "右眼等效球镜度"},
        "left_dilated_se": {"type": "float", "supports_range": "true", "display_name": "左眼散瞳等效球镜度"},
        "right_dilated_se": {"type": "float", "supports_range": "true", "display_name": "右眼散瞳等效球镜度"},
        "right_dilated_sphere": {"type": "float", "supports_range": "true", "display_name": "右眼散瞳球镜"},
        "left_dilated_sphere": {"type": "float", "supports_range": "true", "display_name": "左眼散瞳球镜"},
        "right_dilated_cylinder": {"type": "float", "supports_range": "true", "display_name": "右眼散瞳柱镜"},
        "left_dilated_cylinder": {"type": "float", "supports_range": "true", "display_name": "左眼散瞳柱镜"},
        "right_dilated_axis": {"type": "float", "supports_range": "true", "display_name": "右眼散瞳轴位"},
        "left_dilated_axis": {"type": "float", "supports_range": "true", "display_name": "左眼散瞳轴位"},
        "right_dilated_vision": {"type": "float", "supports_range": "true", "display_name": "右眼散瞳视力"},
        "left_dilated_vision": {"type": "float", "supports_range": "true", "display_name": "左眼散瞳视力"},
        "right_keratometry_K1": {"type": "float", "supports_range": "true", "display_name": "右眼角膜曲率K1"},
        "left_keratometry_K1": {"type": "float", "supports_range": "true", "display_name": "左眼角膜曲率K1"},
        "right_keratometry_K2": {"type": "float", "supports_range": "true", "display_name": "右眼角膜曲率K2"},
        "left_keratometry_K2": {"type": "float", "supports_range": "true", "display_name": "左眼角膜曲率K2"},
        "right_axial_length": {"type": "float", "supports_range": "true", "display_name": "右眼眼轴"},
        "left_axial_length": {"type": "float", "supports_range": "true", "display_name": "左眼眼轴"},
        "right_anterior_depth": {"type": "float", "supports_range": "true", "display_name": "右眼前房深度"},
        "left_anterior_depth": {"type": "float", "supports_range": "true", "display_name": "左眼前房深度"},
        "left_vision_level": {"type": "string", "display_name": "左眼视力等级", "input_type": "select", "options_source": "vision_level_options"},
        "right_vision_level": {"type": "string", "display_name": "右眼视力等级", "input_type": "select", "options_source": "vision_level_options"},
        "comprehensive_vision_level": {"type": "string", "display_name": "综合视力等级", "input_type": "select", "options_source": "vision_level_options"},
        "vision_level": {"type": "string", "display_name": "视力水平分级", "input_type": "select", "options_source": "vision_level_options"},
        "myopia_degree": {"type": "string", "display_name": "近视程度分级", "input_type": "select", "options_source": "myopia_degree_options"},
        "baseline_left_naked_change": {"type": "float", "display_name": "左眼裸眼视力基线变化"},
        "baseline_right_naked_change": {"type": "float", "display_name": "右眼裸眼视力基线变化"},
        "baseline_left_sphere_change": {"type": "float", "display_name": "左眼球镜基线变化"},
        "baseline_right_sphere_change": {"type": "float", "display_name": "右眼球镜基线变化"},
        "baseline_left_se_change": {"type": "float", "display_name": "左眼SE基线变化"},
        "baseline_right_se_change": {"type": "float", "display_name": "右眼SE基线变化"},
        "baseline_left_cylinder_change": {"type": "float", "display_name": "左眼柱镜基线变化"},
        "baseline_right_cylinder_change": {"type": "float", "display_name": "右眼柱镜基线变化"},
        "baseline_left_axis_change": {"type": "float", "display_name": "左眼轴位基线变化"},
        "baseline_right_axis_change": {"type": "float", "display_name": "右眼轴位基线变化"},
        "baseline_left_vision_effect": {"type": "string", "display_name": "左眼视力干预效果", "input_type": "select", "options_source": "intervention_effect_options"},
        "baseline_right_vision_effect": {"type": "string", "display_name": "右眼视力干预效果", "input_type": "select", "options_source": "intervention_effect_options"},
        "baseline_left_se_effect": {"type": "string", "display_name": "左眼SE干预效果", "input_type": "select", "options_source": "intervention_effect_options"},
        "baseline_right_se_effect": {"type": "string", "display_name": "右眼SE干预效果", "input_type": "select", "options_source": "intervention_effect_options"},
        "baseline_left_sphere_effect": {"type": "string", "display_name": "左眼球镜干预效果", "input_type": "select", "options_source": "intervention_effect_options"},
        "baseline_right_sphere_effect": {"type": "string", "display_name": "右眼球镜干预效果", "input_type": "select", "options_source": "intervention_effect_options"},
        "baseline_left_cylinder_effect": {"type": "string", "display_name": "左眼柱镜干预效果", "input_type": "select", "options_source": "intervention_effect_options"},
        "baseline_right_cylinder_effect": {"type": "string", "display_name": "右眼柱镜干预效果", "input_type": "select", "options_source": "intervention_effect_options"},
        "baseline_left_axis_effect": {"type": "string", "display_name": "左眼轴位干预效果", "input_type": "select", "options_source": "intervention_effect_options"},
        "baseline_right_axis_effect": {"type": "string", "display_name": "右眼轴位干预效果", "input_type": "select", "options_source": "intervention_effect_options"},
        "remarks": {"type": "text", "display_name": "备注"},
        "equipment_model": {"type": "string", "display_name": "设备型号"},
        "eye_fatigue": {"type": "string", "display_name": "眼疲劳状况", "input_type": "select", "options_source": "eye_fatigue_options"},
        "other_info": {"type": "text", "display_name": "其他情况"},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"},
        "actions": {"type": "actions", "display_name": "操作", "table": "virtual", "buttons": ["详情", "删除", "日志"]}
    },
    "intervention_records": {
        "id": {"type": "int", "display_name": "干预记录ID"},
        "student_id": {"type": "int", "display_name": "学生ID", "required": True},
        "intervention_date": {"type": "date", "display_name": "干预日期", "required": True},
        "date": {"type": "date", "display_name": "干预日期(兼容字段)"},
        "operation_time": {"type": "time", "display_name": "操作时间"},
        "intervention_type": {"type": "string", "display_name": "干预方式", "input_type": "select", "options_source": "intervention_type_options"},
        "operator": {"type": "string", "display_name": "操作医生", "max_length": 50},
        "duration_minutes": {"type": "int", "display_name": "操作时长(分钟)"},
        "operation_location": {"type": "string", "display_name": "操作地点", "max_length": 100, "input_type": "select", "options_source": "operation_location_options"},
        "operation_tools": {"type": "json", "display_name": "操作工具"},
        "consumed_materials": {"type": "json", "display_name": "消耗材料"},
        "operation_sites": {"type": "json", "display_name": "操作部位"},
        "acupoints": {"type": "json", "display_name": "穴位选择"},
        "press_methods": {"type": "json", "display_name": "贴压方式"},
        "press_strength": {"type": "string", "display_name": "按压强度", "max_length": 20, "default": "中度"},
        "press_frequency": {"type": "int", "display_name": "按压频率"},
        "is_home_intervention": {"type": "bool", "display_name": "是否家庭干预", "default": False},
        "home_operator": {"type": "string", "display_name": "家长姓名", "max_length": 50},
        "home_operator_relation": {"type": "string", "display_name": "家长关系", "max_length": 20},
        "related_hospital_record_id": {"type": "int", "display_name": "关联医院记录ID"},
        "home_intervention_day": {"type": "int", "display_name": "家庭干预第几天"},
        "daily_frequency": {"type": "int", "display_name": "当日操作次数"},
        "parent_feedback": {"type": "string", "display_name": "家长反馈"},
        "child_cooperation": {"type": "string", "display_name": "孩子配合度"},
        "daily_effect_rating": {"type": "string", "display_name": "每日效果评价"},
        "upload_source": {"type": "string", "display_name": "数据来源", "max_length": 20},
        "immediate_effect": {"type": "string", "display_name": "即时效果"},
        "cooperation_level": {"type": "string", "display_name": "配合程度"},
        "patient_reaction": {"type": "json", "display_name": "患者反应"},
        "details": {"type": "string", "display_name": "操作记录/补充说明"},
        "student_feedback": {"type": "string", "display_name": "学生反馈"},
        "data_year": {"type": "string", "display_name": "数据年份"},
        "is_imported": {"type": "bool", "display_name": "是否导入数据", "default": False},
        "import_source": {"type": "string", "display_name": "导入来源"},
        "session_number": {"type": "int", "display_name": "年度干预次序"},
        "global_sequence": {"type": "int", "display_name": "全局干预次序"},
        "operation_data": {"type": "json", "display_name": "操作扩展数据"},
        # 累计统计字段（技术文档B第4.3.1节）
        "guasha_count": {"type": "int", "display_name": "刮痧累计次数", "default": 0},
        "aigiu_count": {"type": "int", "display_name": "艾灸累计次数", "default": 0},
        "erxue_yawan_count": {"type": "int", "display_name": "耳穴压丸累计次数", "default": 0},
        "zhongyao_xunzheng_count": {"type": "int", "display_name": "中药熏蒸累计次数", "default": 0},
        "rejiu_training_count": {"type": "int", "display_name": "热灸训练累计次数", "default": 0},
        "reci_pulse_count": {"type": "int", "display_name": "热磁脉冲累计次数", "default": 0},
        "baoguan_count": {"type": "int", "display_name": "拔罐累计次数", "default": 0},
        
        # 兼容性字段（标记为废弃）
        "guasha": {"type": "bool", "display_name": "刮痧", "default": False},
        "aigiu": {"type": "bool", "display_name": "艾灸", "default": False},
        "erxue_yawan": {"type": "bool", "display_name": "耳穴压丸", "default": False},
        "zhongyao_xunzheng": {"type": "bool", "display_name": "中药熏蒸", "default": False},
        "rejiu_training": {"type": "bool", "display_name": "热灸训练", "default": False},
        "reci_pulse": {"type": "bool", "display_name": "热磁脉冲", "default": False},
        "baoguan": {"type": "bool", "display_name": "拔罐", "default": False},
        "scraping_intensity": {"type": "string", "display_name": "刮痧强度"},
        "scraping_direction": {"type": "string", "display_name": "刮痧方向"},
        "scraping_duration": {"type": "int", "display_name": "刮痧时长(分钟)"},
        "skin_reaction": {"type": "json", "display_name": "皮肤反应"},
        "moxibustion_type": {"type": "string", "display_name": "艾灸类型"},
        "temperature_level": {"type": "string", "display_name": "温度等级"},
        "moxibustion_distance": {"type": "int", "display_name": "施灸距离(厘米)"},
        "heat_sensation": {"type": "string", "display_name": "热感程度"},
        "steam_temperature": {"type": "int", "display_name": "熏蒸温度(℃)"},
        "medicine_formula": {"type": "string", "display_name": "药物配方"},
        "steam_intensity": {"type": "string", "display_name": "熏蒸强度"},
        "comfort_level": {"type": "string", "display_name": "舒适度"},
        "intensity_level": {"type": "string", "display_name": "强度档位"},
        "treatment_mode": {"type": "string", "display_name": "治疗模式"},
        "temperature_feedback": {"type": "string", "display_name": "温度反馈"},
        "training_effect": {"type": "string", "display_name": "训练效果"},
        "pulse_frequency": {"type": "int", "display_name": "脉冲频率(Hz)"},
        "magnetic_intensity": {"type": "string", "display_name": "磁场强度档位"},
        "pulse_pattern": {"type": "string", "display_name": "脉冲模式"},
        "sensation_feedback": {"type": "string", "display_name": "感觉反馈"},
        "suction_strength": {"type": "string", "display_name": "负压强度"},
        "cupping_method": {"type": "string", "display_name": "拔罐方式"},
        "details": {"type": "text", "display_name": "干预详情"},
        "student_feedback": {"type": "text", "display_name": "学生反馈"},
        "parent_feedback": {"type": "text", "display_name": "家长反馈"},
        "daily_effect_rating": {"type": "int", "display_name": "日效果评分"},
        "moxibustion_distance": {"type": "string", "display_name": "艾灸距离"},
        "skin_color_change": {"type": "string", "display_name": "皮肤颜色变化"},
        "skin_reaction": {"type": "string", "display_name": "皮肤反应"},
        "cupping_marks": {"type": "string", "display_name": "罐印情况"},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    "followup_records": {
        "id": {"type": "int", "display_name": "随访记录ID"},
        "student_id": {"type": "int", "display_name": "学生ID", "required": True},
        "followup_date": {"type": "date", "display_name": "随访日期", "required": True, "input_type": "date"},
        "followup_time": {"type": "time", "display_name": "随访时间", "input_type": "time"},
        "interviewer": {"type": "string", "display_name": "随访员", "max_length": 50, "required": True, "input_type": "text"},
        "interviewee": {"type": "string", "display_name": "被访者", "max_length": 50, "required": True, "input_type": "text"},
        "interviewee_relation": {"type": "string", "display_name": "关系", "max_length": 20, "required": True, "input_type": "select", "options_source": "interviewee_relation_options"},
        "contact_method": {"type": "string", "display_name": "联系方式", "max_length": 20, "required": True, "input_type": "select", "options_source": "contact_method_options"},
        "followup_duration": {"type": "int", "display_name": "随访时长(分钟)", "input_type": "number"},
        "followup_type": {"type": "string", "display_name": "随访类型", "input_type": "select", "options_source": "followup_type_options"},
        "intervention_satisfaction": {"type": "string", "display_name": "干预满意度", "max_length": 20, "input_type": "select", "options_source": "intervention_satisfaction_options"},
        "intervention_effect_evaluation": {"type": "string", "display_name": "干预效果评价", "max_length": 20, "input_type": "select", "options_source": "intervention_effect_evaluation_options"},
        "intervention_compliance": {"type": "string", "display_name": "干预依从性", "max_length": 20, "input_type": "select", "options_source": "intervention_compliance_options"},
        "side_effects": {"type": "string", "display_name": "不良反应", "max_length": 200, "input_type": "textarea"},
        "vision_change_perception": {"type": "string", "display_name": "视力变化感知", "max_length": 20, "input_type": "select", "options_source": "vision_change_perception_options"},
        "vision_improvement_details": {"type": "text", "display_name": "视力改善细节", "input_type": "textarea"},
        "vision_concern_areas": {"type": "text", "display_name": "视力关注问题", "input_type": "textarea"},
        "daily_eye_use_time": {"type": "string", "display_name": "每日用眼时间", "max_length": 50, "input_type": "text"},
        "content": {"type": "text", "display_name": "随访内容", "input_type": "textarea"},
        "feedback": {"type": "text", "display_name": "反馈信息", "input_type": "textarea"},
        "data_year": {"type": "string", "display_name": "数据年份", "max_length": 4, "input_type": "text"},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    "vision_record_logs": {
        "id": {"type": "int", "display_name": "日志ID"},
        "record_id": {"type": "int", "display_name": "视力记录ID", "required": True},
        "student_id": {"type": "int", "display_name": "学生ID", "required": True},
        "action": {"type": "string", "display_name": "操作类型", "choices": ["CREATE", "UPDATE", "DELETE", "RESTORE"], "required": True},
        "operator": {"type": "string", "display_name": "操作人", "max_length": 100, "required": True},
        "operation_time": {"type": "datetime", "display_name": "操作时间"},
        "old_content": {"type": "text", "display_name": "修改前内容"},
        "new_content": {"type": "text", "display_name": "修改后内容"},
        "operation_desc": {"type": "string", "display_name": "操作描述"},
        "ip_address": {"type": "string", "display_name": "IP地址", "max_length": 50},
        "user_agent": {"type": "string", "display_name": "UserAgent", "max_length": 500},
        "created_at": {"type": "datetime", "display_name": "日志创建时间"}
    },
    "followup_record_logs": {
        "id": {"type": "int", "display_name": "日志ID"},
        "record_id": {"type": "int", "display_name": "随访记录ID", "required": True},
        "student_id": {"type": "int", "display_name": "学生ID", "required": True},
        "action": {"type": "string", "display_name": "操作类型", "required": True},
        "operator": {"type": "string", "display_name": "操作人", "max_length": 50},
        "old_content": {"type": "text", "display_name": "修改前内容"},
        "new_content": {"type": "text", "display_name": "修改后内容"},
        "created_at": {"type": "datetime", "display_name": "日志创建时间"}
    },
    "student_archive_logs": {
        "record_id": {"type": "int", "display_name": "学生档案记录ID", "required": True},
        "student_id": {"type": "int", "display_name": "学生ID", "required": True},
        "action": {"type": "string", "display_name": "操作类型", "choices": ["CREATE", "UPDATE", "DELETE", "RESTORE"], "required": True},
        "operator": {"type": "string", "display_name": "操作人", "max_length": 100, "required": True},
        "operation_time": {"type": "datetime", "display_name": "操作时间"},
        "old_content": {"type": "string", "display_name": "修改前内容"},
        "new_content": {"type": "string", "display_name": "修改后内容"},
        "operation_desc": {"type": "string", "display_name": "操作描述"},
        "ip_address": {"type": "string", "display_name": "IP地址", "max_length": 50},
        "user_agent": {"type": "string", "display_name": "UserAgent", "max_length": 500},
        "created_at": {"type": "datetime", "display_name": "日志创建时间"}
    },
    "users": {
        "id": {"type": "int", "display_name": "用户ID"},
        "username": {"type": "string", "display_name": "用户名", "max_length": 50, "required": True, "unique": True},
        "password_hash": {"type": "string", "display_name": "密码哈希", "max_length": 255, "required": True},
        "status": {"type": "string", "display_name": "用户状态", "max_length": 20, "required": True},
        "last_login": {"type": "datetime", "display_name": "最后登录时间"},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "real_name": {"type": "string", "display_name": "真实姓名", "max_length": 50},
        "mobile": {"type": "string", "display_name": "手机号", "max_length": 20},
        "email": {"type": "string", "display_name": "邮箱", "max_length": 100},
        "gender": {"type": "string", "display_name": "性别", "input_type": "select", "options_source": "gender_options", "max_length": 10},
        "department": {"type": "string", "display_name": "部门", "max_length": 100},
        "position": {"type": "string", "display_name": "岗位", "max_length": 100},
        "remark": {"type": "string", "display_name": "备注", "max_length": 255},
        "birth_date": {"type": "date", "display_name": "出生日期"},
        "address": {"type": "string", "display_name": "联系地址", "max_length": 255},
        "openid": {"type": "string", "display_name": "微信OpenID", "max_length": 100, "unique": True},
        "user_type": {"type": "string", "display_name": "用户类型", "max_length": 20},
        "bind_status": {"type": "string", "display_name": "绑定状态", "max_length": 20},
        "student_id": {"type": "int", "display_name": "关联学生ID"},
        "nickname": {"type": "string", "display_name": "昵称", "max_length": 50},
        "avatar": {"type": "string", "display_name": "头像URL", "max_length": 500}
    },
    "roles": {
        "id": {"type": "int", "display_name": "角色ID"},
        "name": {"type": "string", "display_name": "角色名", "max_length": 50, "unique": True, "required": True},
        "description": {"type": "string", "display_name": "角色描述", "max_length": 255},
        "status": {"type": "string", "display_name": "状态", "input_type": "select", "options": ["active", "inactive"], "default": "active"}
    },
    "user_roles": {
        "id": {"type": "int", "display_name": "用户角色ID"},
        "user_id": {"type": "int", "display_name": "用户ID", "required": True},
        "role_id": {"type": "int", "display_name": "角色ID", "required": True}
    },
    "system_logs": {
        "id": {"type": "int", "display_name": "日志ID"},
        "user_id": {"type": "int", "display_name": "操作用户ID"},
        "action": {"type": "string", "display_name": "操作类型", "input_type": "select", "options": ["CREATE", "UPDATE", "DELETE", "LOGIN", "LOGOUT", "RESTORE", "OTHER"]},
        "target_id": {"type": "int", "display_name": "目标ID"},
        "detail": {"type": "text", "display_name": "操作详情"},
        "old_content": {"type": "text", "display_name": "修改前内容"},
        "new_content": {"type": "text", "display_name": "修改后内容"},
        "ip_address": {"type": "string", "display_name": "IP地址", "max_length": 50},
        "operation_time": {"type": "datetime", "display_name": "操作时间"},
        "created_at": {"type": "datetime", "display_name": "创建时间"}
    },
    "login_logs": {
        "id": {"type": "int", "display_name": "登录日志ID"},
        "user_id": {"type": "int", "display_name": "用户ID"},
        "username": {"type": "string", "display_name": "用户名"},
        "login_time": {"type": "datetime", "display_name": "登录时间"},
        "ip_address": {"type": "string", "display_name": "IP地址", "max_length": 50},
        "user_agent": {"type": "string", "display_name": "UserAgent", "max_length": 500},
        "status": {"type": "string", "display_name": "登录状态", "input_type": "select", "options": ["success", "fail"]}
    },
    "menu": {
        "id": {"type": "int", "display_name": "菜单ID"},
        "name": {"type": "string", "display_name": "菜单名称", "max_length": 50, "required": True},
        "parent_id": {"type": "int", "display_name": "父菜单ID"},
        "path": {"type": "string", "display_name": "路由路径", "max_length": 100},
        "icon": {"type": "string", "display_name": "图标", "max_length": 50},
        "order": {"type": "int", "display_name": "排序"},
        "visible": {"type": "bool", "display_name": "是否可见", "default": True},
        "permission": {"type": "string", "display_name": "权限标识", "max_length": 50},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    
    # ==================== 社交分享模块字段配置 ====================
    "social_shares": {
        "id": {"type": "int", "display_name": "分享ID"},
        "user_id": {"type": "int", "display_name": "分享用户ID", "required": True},
        "student_id": {"type": "int", "display_name": "关联学生ID"},
        "title": {"type": "string", "display_name": "分享标题", "required": True, "max_length": 200},
        "content": {"type": "text", "display_name": "分享内容", "required": True},
        "images": {"type": "text", "display_name": "图片URL列表"},
        "share_type": {"type": "string", "display_name": "分享类型", "input_type": "select", "options_source": "share_type_options", "default": "intervention"},
        "tags": {"type": "string", "display_name": "标签", "max_length": 500},
        "view_count": {"type": "int", "display_name": "浏览次数", "default": 0},
        "like_count": {"type": "int", "display_name": "点赞数", "default": 0},
        "comment_count": {"type": "int", "display_name": "评论数", "default": 0},
        "share_count": {"type": "int", "display_name": "分享数", "default": 0},
        "status": {"type": "string", "display_name": "状态", "input_type": "select", "options_source": "share_status_options", "default": "active"},
        "audit_reason": {"type": "string", "display_name": "审核拒绝原因", "max_length": 500},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    "social_share_likes": {
        "id": {"type": "int", "display_name": "点赞ID"},
        "share_id": {"type": "int", "display_name": "分享ID", "required": True},
        "user_id": {"type": "int", "display_name": "点赞用户ID", "required": True},
        "created_at": {"type": "datetime", "display_name": "点赞时间"}
    },
    "social_share_comments": {
        "id": {"type": "int", "display_name": "评论ID"},
        "share_id": {"type": "int", "display_name": "分享ID", "required": True},
        "user_id": {"type": "int", "display_name": "评论用户ID", "required": True},
        "parent_id": {"type": "int", "display_name": "父评论ID"},
        "content": {"type": "text", "display_name": "评论内容", "required": True},
        "like_count": {"type": "int", "display_name": "点赞数量", "default": 0},
        "status": {"type": "string", "display_name": "状态", "input_type": "select", "options_source": "comment_status_options", "default": "active"},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    "user_follows": {
        "id": {"type": "int", "display_name": "关注ID"},
        "follower_id": {"type": "int", "display_name": "关注者ID", "required": True},
        "following_id": {"type": "int", "display_name": "被关注者ID", "required": True},
        "created_at": {"type": "datetime", "display_name": "关注时间"}
    },
    "content_reports": {
        "id": {"type": "int", "display_name": "举报ID"},
        "reporter_id": {"type": "int", "display_name": "举报用户ID", "required": True},
        "content_type": {"type": "string", "display_name": "内容类型", "input_type": "select", "options_source": "content_type_options"},
        "content_id": {"type": "int", "display_name": "内容ID", "required": True},
        "report_reason": {"type": "string", "display_name": "举报原因", "input_type": "select", "options_source": "report_reason_options"},
        "report_detail": {"type": "text", "display_name": "举报详情"},
        "status": {"type": "string", "display_name": "处理状态", "input_type": "select", "options_source": "report_status_options", "default": "pending"},
        "admin_remark": {"type": "text", "display_name": "管理员备注"},
        "processed_at": {"type": "datetime", "display_name": "处理时间"},
        "created_at": {"type": "datetime", "display_name": "举报时间"}
    },
    
    # ==================== 医患咨询模块字段配置 ====================
    "medical_consults": {
        "id": {"type": "int", "display_name": "咨询ID"},
        "user_id": {"type": "int", "display_name": "用户ID", "required": True},
        "student_id": {"type": "int", "display_name": "学生ID"},
        "title": {"type": "string", "display_name": "咨询标题", "required": True, "max_length": 200},
        "content": {"type": "text", "display_name": "咨询内容", "required": True},
        "category": {"type": "string", "display_name": "咨询分类", "input_type": "select", "options_source": "consult_category_options"},
        "priority": {"type": "string", "display_name": "优先级", "input_type": "select", "options_source": "consult_priority_options", "default": "normal"},
        "status": {"type": "string", "display_name": "状态", "input_type": "select", "options_source": "consult_status_options", "default": "pending"},
        "images": {"type": "json", "display_name": "相关图片"},
        "doctor_id": {"type": "int", "display_name": "医生ID"},
        "doctor_name": {"type": "string", "display_name": "医生姓名", "max_length": 100},
        "doctor_title": {"type": "string", "display_name": "医生职称", "max_length": 100},
        "reply_content": {"type": "text", "display_name": "回复内容"},
        "reply_images": {"type": "json", "display_name": "回复图片"},
        "replied_at": {"type": "datetime", "display_name": "回复时间"},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    "consult_attachments": {
        "id": {"type": "int", "display_name": "附件ID"},
        "consult_id": {"type": "int", "display_name": "咨询ID", "required": True},
        "file_name": {"type": "string", "display_name": "文件名", "max_length": 255},
        "file_path": {"type": "string", "display_name": "文件路径", "max_length": 500},
        "file_size": {"type": "int", "display_name": "文件大小"},
        "file_type": {"type": "string", "display_name": "文件类型", "max_length": 50},
        "uploaded_by": {"type": "string", "display_name": "上传者", "max_length": 20},
        "created_at": {"type": "datetime", "display_name": "创建时间"}
    },
    "consult_categories": {
        "id": {"type": "int", "display_name": "分类ID"},
        "name": {"type": "string", "display_name": "分类名称", "required": True, "max_length": 100},
        "code": {"type": "string", "display_name": "分类代码", "max_length": 50},
        "description": {"type": "text", "display_name": "分类描述"},
        "sort_order": {"type": "int", "display_name": "排序", "default": 0},
        "is_active": {"type": "bool", "display_name": "是否启用", "default": True},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    
    # ==================== 通知系统模块字段配置 ====================
    "notifications": {
        "id": {"type": "int", "display_name": "通知ID"},
        "user_id": {"type": "int", "display_name": "用户ID", "required": True},
        "title": {"type": "string", "display_name": "通知标题", "required": True, "max_length": 200},
        "content": {"type": "text", "display_name": "通知内容", "required": True},
        "notification_type": {"type": "string", "display_name": "通知类型", "max_length": 50},
        "priority": {"type": "string", "display_name": "优先级", "input_type": "select", "options_source": "notification_priority_options", "default": "normal"},
        "status": {"type": "string", "display_name": "状态", "max_length": 20},
        "read_at": {"type": "datetime", "display_name": "阅读时间"},
        "created_by": {"type": "int", "display_name": "创建者ID"},
        "related_id": {"type": "int", "display_name": "关联ID"},
        "related_type": {"type": "string", "display_name": "关联类型", "max_length": 50},
        "template_id": {"type": "string", "display_name": "模板ID", "max_length": 100},
        "target_users": {"type": "string", "display_name": "目标用户", "max_length": 50},
        "scheduled_at": {"type": "datetime", "display_name": "计划发送时间"},
        "published_at": {"type": "datetime", "display_name": "发布时间"},
        "sent_at": {"type": "datetime", "display_name": "发送时间"},
        "sent_count": {"type": "int", "display_name": "发送次数"},
        "expire_at": {"type": "datetime", "display_name": "过期时间"},
        "wechat_sent": {"type": "bool", "display_name": "微信已发送", "default": False},
        "wechat_sent_at": {"type": "datetime", "display_name": "微信发送时间"},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    "notification_settings": {
        "id": {"type": "int", "display_name": "设置ID"},
        "user_id": {"type": "int", "display_name": "用户ID", "required": True},
        "notification_type": {"type": "string", "display_name": "通知类型", "input_type": "select", "options_source": "notification_type_options"},
        "enabled": {"type": "bool", "display_name": "是否启用", "default": True},
        "app_enabled": {"type": "bool", "display_name": "APP通知启用", "default": True},
        "wechat_enabled": {"type": "bool", "display_name": "微信通知启用", "default": True},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    "wechat_templates": {
        "id": {"type": "int", "display_name": "模板ID"},
        "template_id": {"type": "string", "display_name": "微信模板ID", "required": True, "max_length": 100},
        "notification_type": {"type": "string", "display_name": "通知类型", "max_length": 50},
        "template_name": {"type": "string", "display_name": "模板名称", "max_length": 100},
        "title": {"type": "string", "display_name": "模板标题", "max_length": 200},
        "content_template": {"type": "text", "display_name": "内容模板"},
        "variables": {"type": "text", "display_name": "变量配置"},
        "status": {"type": "string", "display_name": "状态", "max_length": 20},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    "notification_logs": {
        "id": {"type": "int", "display_name": "日志ID"},
        "notification_id": {"type": "int", "display_name": "通知ID"},
        "send_type": {"type": "string", "display_name": "发送类型", "max_length": 20},
        "status": {"type": "string", "display_name": "发送状态", "input_type": "select", "options_source": "notification_send_status_options"},
        "error_message": {"type": "text", "display_name": "错误信息"},
        "retry_count": {"type": "int", "display_name": "重试次数"},
        "sent_at": {"type": "datetime", "display_name": "发送时间"}
    },
    
    # ==================== 文档管理模块字段配置 ====================
    "documents": {
        "id": {"type": "int", "display_name": "文档ID"},
        "title": {"type": "string", "display_name": "文档标题", "required": True, "max_length": 200},
        "content": {"type": "text", "display_name": "文档内容", "required": True},
        "document_type": {"type": "string", "display_name": "文档类型", "input_type": "select"},
        "version": {"type": "string", "display_name": "版本号", "max_length": 20},
        "status": {"type": "string", "display_name": "状态"},
        "created_by": {"type": "int", "display_name": "创建者ID"},
        "reviewed_by": {"type": "int", "display_name": "审核者ID"},
        "effective_date": {"type": "datetime", "display_name": "生效时间"},
        "expiry_date": {"type": "datetime", "display_name": "过期时间"},
        "published_at": {"type": "datetime", "display_name": "发布时间"},
        "is_mandatory": {"type": "bool", "display_name": "是否必读", "default": False},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    "user_document_agreements": {
        "id": {"type": "int", "display_name": "协议ID"},
        "user_id": {"type": "int", "display_name": "用户ID", "required": True},
        "document_id": {"type": "int", "display_name": "文档ID", "required": True},
        "document_version": {"type": "string", "display_name": "文档版本", "max_length": 20},
        "agreed_at": {"type": "datetime", "display_name": "同意时间"},
        "ip_address": {"type": "string", "display_name": "IP地址", "max_length": 45},
        "user_agent": {"type": "string", "display_name": "用户代理", "max_length": 500}
    },
    "user_privacy_settings": {
        "id": {"type": "int", "display_name": "隐私设置ID"},
        "user_id": {"type": "int", "display_name": "用户ID", "required": True},
        "behavior_analysis": {"type": "bool", "display_name": "行为分析", "default": True},
        "location_services": {"type": "bool", "display_name": "位置服务", "default": False},
        "third_party_share": {"type": "bool", "display_name": "第三方分享", "default": False},
        "personalized_recommend": {"type": "bool", "display_name": "个性化推荐", "default": True},
        "data_retention": {"type": "string", "display_name": "数据保留", "max_length": 20, "default": "auto"},
        "marketing_messages": {"type": "bool", "display_name": "营销消息", "default": False},
        "data_collection": {"type": "bool", "display_name": "数据收集", "default": True},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    
    # ==================== 反馈系统模块字段配置 ====================
    "feedbacks": {
        "id": {"type": "int", "display_name": "反馈ID"},
        "user_id": {"type": "int", "display_name": "用户ID", "required": True},
        "title": {"type": "string", "display_name": "反馈标题", "required": True, "max_length": 200},
        "content": {"type": "text", "display_name": "反馈内容", "required": True},
        "category": {"type": "string", "display_name": "反馈分类", "max_length": 50},
        "status": {"type": "string", "display_name": "处理状态", "input_type": "select", "options_source": "feedback_status_options", "default": "pending"},
        "priority": {"type": "string", "display_name": "优先级", "input_type": "select", "options_source": "feedback_priority_options", "default": "normal"},
        "images": {"type": "json", "display_name": "附图"},
        "contact_info": {"type": "string", "display_name": "联系方式", "max_length": 200},
        "assigned_to": {"type": "int", "display_name": "分配给"},
        "resolution": {"type": "text", "display_name": "处理结果"},
        "resolved_at": {"type": "datetime", "display_name": "解决时间"},
        "ip_address": {"type": "string", "display_name": "IP地址", "max_length": 45},
        "user_agent": {"type": "string", "display_name": "用户代理", "max_length": 500},
        "created_at": {"type": "datetime", "display_name": "创建时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    "feedback_replies": {
        "id": {"type": "int", "display_name": "回复ID"},
        "feedback_id": {"type": "int", "display_name": "反馈ID", "required": True},
        "user_id": {"type": "int", "display_name": "用户ID"},
        "content": {"type": "text", "display_name": "回复内容", "required": True},
        "images": {"type": "json", "display_name": "回复图片"},
        "is_admin_reply": {"type": "bool", "display_name": "是否管理员回复", "default": False},
        "created_at": {"type": "datetime", "display_name": "回复时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    
    # ==================== 权限管理补充字段配置 ====================
    "role_permissions": {
        "id": {"type": "int", "display_name": "角色权限ID"},
        "role_id": {"type": "int", "display_name": "角色ID", "required": True},
        "permission_id": {"type": "int", "display_name": "权限ID", "required": True}
    },
    "role_applications": {
        "id": {"type": "int", "display_name": "申请ID"},
        "user_id": {"type": "int", "display_name": "用户ID", "required": True},
        "role_id": {"type": "int", "display_name": "角色ID", "required": True},
        "reason": {"type": "text", "display_name": "申请理由"},
        "status": {"type": "string", "display_name": "申请状态", "input_type": "select", "options_source": "application_status_options", "default": "pending"},
        "reviewer_id": {"type": "int", "display_name": "审核者ID"},
        "review_reason": {"type": "text", "display_name": "审核原因"},
        "review_time": {"type": "datetime", "display_name": "审核时间"},
        "attachments": {"type": "text", "display_name": "附件"},
        "created_at": {"type": "datetime", "display_name": "申请时间"},
        "updated_at": {"type": "datetime", "display_name": "更新时间"}
    },
    "permissions": {
        "id": {"type": "int", "display_name": "权限ID"},
        "name": {"type": "string", "display_name": "权限名称", "required": True},
        "code": {"type": "string", "display_name": "权限代码", "max_length": 100},
        "description": {"type": "string", "display_name": "权限描述"},
        "status": {"type": "string", "display_name": "状态", "max_length": 20}
    },
    "intervention_record_logs": {
        "id": {"type": "int", "display_name": "日志ID"},
        "record_id": {"type": "int", "display_name": "记录ID", "required": True},
        "student_id": {"type": "int", "display_name": "学生ID", "required": True},
        "action": {"type": "string", "display_name": "操作类型", "required": True},
        "operator": {"type": "string", "display_name": "操作者", "required": True},
        "operator_type": {"type": "string", "display_name": "操作者类型", "max_length": 20},
        "operation_time": {"type": "datetime", "display_name": "操作时间"},
        "old_content": {"type": "text", "display_name": "旧内容"},
        "new_content": {"type": "text", "display_name": "新内容"},
        "operation_desc": {"type": "string", "display_name": "操作描述"},
        "ip_address": {"type": "string", "display_name": "IP地址"},
        "user_agent": {"type": "string", "display_name": "用户代理"},
        "home_operator": {"type": "string", "display_name": "家庭操作者", "max_length": 50},
        "upload_source": {"type": "string", "display_name": "上传来源", "max_length": 20},
        "is_home_intervention": {"type": "bool", "display_name": "是否家庭干预"},
        "created_at": {"type": "datetime", "display_name": "创建时间"}
    },
    "student_archive_logs": {
        "id": {"type": "int", "display_name": "日志ID"},
        "student_id": {"type": "int", "display_name": "学生ID", "required": True},
        "action": {"type": "string", "display_name": "操作类型", "required": True},
        "operator": {"type": "string", "display_name": "操作者", "required": True},
        "operation_time": {"type": "datetime", "display_name": "操作时间"},
        "old_content": {"type": "text", "display_name": "旧内容"},
        "new_content": {"type": "text", "display_name": "新内容"},
        "operation_desc": {"type": "string", "display_name": "操作描述"},
        "ip_address": {"type": "string", "display_name": "IP地址"},
        "user_agent": {"type": "string", "display_name": "用户代理"},
        "module_source": {"type": "string", "display_name": "模块来源"},
        "created_at": {"type": "datetime", "display_name": "创建时间"}
    }
}

# ==================== 全局唯一字段配置表结束 ====================

# 配置项注册表
CONFIG_REGISTRY = {
    # ==================== 基础配置 ====================
    
    # 数据库连接配置
    "DB_CONFIG": {
        "host": "localhost",
        "port": 3306,
        "user": "root",
        "password": "password",
        "database": "dev_vision"
    },
    
    # Redis缓存配置
    "REDIS_CONFIG": {
        "host": "localhost",
        "port": 6379,
        "db": 0
    },
    
    # 日志文件配置
    "LOGGING_CONFIG": {
        "version": 1,
        "disable_existing_loggers": False,
        "formatters": {
            "simple": {
                "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
            },
            "detailed": {
                "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s [in %(pathname)s:%(lineno)d]"
            }
        },
        "handlers": {
            "console": {
                "class": "logging.StreamHandler",
                "formatter": "simple"
            },
            "file": {
                "class": "logging.FileHandler",
                "filename": "dev_vision.log",
                "formatter": "detailed"
            }
        },
        "loggers": {
            "": {
                "handlers": ["console", "file"],
                "level": "DEBUG",
                "propagate": True
            }
        }
    },
    
    # ==================== 用户资料可编辑字段（前端动态驱动） ====================
    # 说明：仅追加，不移除旧逻辑。前端资料编辑页改为可选使用该配置，解耦硬编码。
    # 字段含义：
    # - field: 字段名（与后端User模型/接口payload一致）
    # - label: 展示名称
    # - type: 输入类型 text/date/select/email
    # - options_source: 若为 select，从 GLOBAL_OPTIONS_CONFIG 获取；否则忽略
    # - required: 是否必填（后端仍再次校验）
    # - max_length: 前端输入限制
    "USER_PROFILE_EDITABLE_FIELDS": [
        {"field": "nickname", "label": "昵称", "type": "text", "required": True, "max_length": 50},
        {"field": "real_name", "label": "真实姓名", "type": "text", "required": False, "max_length": 50},
        {"field": "gender", "label": "性别", "type": "select", "options_source": "gender_options"},
        {"field": "birth_date", "label": "出生日期", "type": "date"},
        {"field": "address", "label": "联系地址", "type": "text", "max_length": 255},
        {"field": "email", "label": "邮箱", "type": "email", "max_length": 100},
        {"field": "mobile", "label": "手机号", "type": "text", "max_length": 20},
        {"field": "avatar", "label": "头像", "type": "image"}
    ],
    
    # ==================== 数据导入模块配置（新增） ====================
    
    # Excel字段映射配置
    "EXCEL_FIELD_MAPPING": {
        # 学生基本信息字段
        '教育ID号': 'education_id', '学校': 'school', '年级': 'grade', '班级': 'class_name',
        '姓名': 'name', '性别': 'gender', '年龄': 'age', '身高': 'height', '体重': 'weight',
        '出生日期': 'birthday', '身份证号码': 'id_card', '联系电话': 'phone', 
        '家长姓名': 'parent_name', '家长电话': 'parent_phone', '联系地址': 'contact_address', '区域': 'region',
        
        # 健康信息字段
        '饮食偏好': 'diet_preference', '运动偏好': 'exercise_preference', '健康教育': 'health_education',
        '既往史': 'past_history', '家族史': 'family_history', '是否早产': 'premature', '过敏史': 'allergy',
        
        # 矫正方式字段
        '框架眼镜': 'frame_glasses', 
        '隐形眼镜': 'contact_lenses', 
        '夜戴角膜塑形镜': 'night_orthokeratology',
        
        # 干预方式字段
        '刮痧': 'guasha', '艾灸': 'aigiu', '中药熏蒸': 'zhongyao_xunzheng',
        '热灸训练': 'rejiu_training', '耳穴压丸': 'erxue_yawan', '热磁脉冲': 'reci_pulse', '拔罐': 'baoguan',
        
        # 检查管理字段映射
        '检查地点（机构）': 'measure_location',
        
        # 基础视力数据字段映射（第一次测量 - 基线候选）
        # 说明：这组数据将使用第1次干预日期作为测量日期
        '右眼-裸眼视力': 'right_eye_naked', 
        '左眼-裸眼视力': 'left_eye_naked',
        '右眼-矫正视力': 'right_eye_corrected', 
        '左眼-矫正视力': 'left_eye_corrected',
        
        # 屈光检查字段映射（第一次测量 - 基线候选）
        '右眼屈光-球镜': 'right_sphere', 
        '右眼屈光-柱镜': 'right_cylinder', 
        '右眼屈光-轴位': 'right_axis',
        '左眼屈光-球镜': 'left_sphere', 
        '左眼屈光-柱镜': 'left_cylinder', 
        '左眼屈光-轴位': 'left_axis',  # 修复：添加缺失的引号

        # 散瞳验光字段映射（第一次测量 - 基线候选）
        '右眼散瞳-球镜': 'right_dilated_sphere', 
        '左眼散瞳-球镜': 'left_dilated_sphere',
        '右眼散瞳-柱镜': 'right_dilated_cylinder', 
        '左眼散瞳-柱镜': 'left_dilated_cylinder',
        '右眼散瞳-轴位': 'right_dilated_axis', 
        '左眼散瞳-轴位': 'left_dilated_axis',

        # 生物测量字段映射（第一次测量 - 基线候选）
        '右眼-角膜曲率K1': 'right_keratometry_K1', 
        '左眼-角膜曲率K1': 'left_keratometry_K1',
        '右眼-角膜曲率K2': 'right_keratometry_K2', 
        '左眼-角膜曲率K2': 'left_keratometry_K2',
        '右眼-眼轴': 'right_axial_length', 
        '左眼-眼轴': 'left_axial_length',
        '右眼-前房深度': 'right_anterior_depth', 
        '左眼-前房深度': 'left_anterior_depth',
        
        # 随访视力数据字段映射（第二次测量 - 干预后随访）
        # 重要说明：以下字段映射到与基线相同的数据库字段，这是正确的设计
        # 通过测量日期和记录序号区分不同的测量记录
        '右眼-干预-裸眼视力': 'right_eye_naked',     # 复用：与基线映射相同字段
        '左眼-干预-裸眼视力': 'left_eye_naked',      # 复用：与基线映射相同字段
        '右眼屈光-干预-球镜': 'right_sphere',        # 复用：与基线映射相同字段
        '右眼屈光-干预-柱镜': 'right_cylinder',      # 复用：与基线映射相同字段
        '右眼屈光-干预-轴位': 'right_axis',          # 复用：与基线映射相同字段
        '左眼屈光-干预-球镜': 'left_sphere',         # 复用：与基线映射相同字段
        '左眼屈光-干预-柱镜': 'left_cylinder',       # 复用：与基线映射相同字段
        '左眼屈光-干预-轴位': 'left_axis',           # 复用：与基线映射相同字段
        '右眼散瞳-干预-球镜': 'right_dilated_sphere', # 复用：与基线映射相同字段
        '右眼散瞳-干预-柱镜': 'right_dilated_cylinder', # 复用：与基线映射相同字段
        '右眼散瞳-干预-轴位': 'right_dilated_axis',   # 复用：与基线映射相同字段
        '左眼散瞳-干预-球镜': 'left_dilated_sphere',  # 复用：与基线映射相同字段
        '左眼散瞳-干预-柱镜': 'left_dilated_cylinder', # 复用：与基线映射相同字段
        '左眼散瞳-干预-轴位': 'left_dilated_axis',    # 复用：与基线映射相同字段
        
        # 其他信息字段映射
        '其他情况': 'other_info', 
        '眼疲劳状况': 'eye_fatigue',
        
        # 干预日期字段映射（用于确定测量时间）
        '第1次干预': 'intervention_date_1', '第2次干预': 'intervention_date_2', '第3次干预': 'intervention_date_3',
        '第4次干预': 'intervention_date_4', '第5次干预': 'intervention_date_5', '第6次干预': 'intervention_date_6',
        '第7次干预': 'intervention_date_7', '第8次干预': 'intervention_date_8', '第9次干预': 'intervention_date_9',
        '第10次干预': 'intervention_date_10', '第11次干预': 'intervention_date_11', '第12次干预': 'intervention_date_12'
    },
    
    # 干预导入默认值配置
    "INTERVENTION_IMPORT_DEFAULTS": {
        'intervention_type': '耳穴压丸',           # 修改：干预方式
        'operator': '曲线社区医生',                # 修改：操作医生
        'operation_time': '10:00',                # 修改：操作时间
        'duration_minutes': 5,                    # 修改：持续时间5分钟
        'press_strength': '中度',                 # 按压强度
        'press_frequency': 30,                    # 按压频率
        'is_imported': True,
        'import_source': 'Excel导入',
        # 新增字段配置
        'operation_tools': ['手动专用粘贴'],
        'consumed_materials': ['王不留行籽', '磁珠'],
        'operation_sites': ['双耳'],
        'acupoints': ['眼', '肝', '肾', '脾', '心', '神门', '枕', '目1', '目2'],
        'press_methods': ['专用胶贴粘贴']
    },
    
    # 日期格式配置
    "DATE_FORMATS": [
        '%Y-%m-%d', '%Y/%m/%d', '%Y.%m.%d', 
        '%Y-%m-%d %H:%M:%S', '%Y/%m/%d %H:%M:%S', 
        '%m/%d/%Y', '%d/%m/%Y', '%Y%m%d'
    ],
    
    # 数据验证模式配置
    "DATA_VALIDATION_PATTERNS": {
        'id_card': r'^\d{17}[\dXx]$',
        'phone': r'^1[3-9]\d{9}$',
        'education_id': r'^\d{7,20}$',
        'parent_phone': r'^1[3-9]\d{9}$'
    },
    
    # 数值验证范围配置
    "NUMERIC_VALIDATION_RANGES": {
        'age': {'min': 3, 'max': 18, 'type': 'integer', 'name': '年龄'},
        'height': {'min': 80, 'max': 200, 'type': 'float', 'name': '身高(cm)'},
        'weight': {'min': 10, 'max': 100, 'type': 'float', 'name': '体重(kg)'},
        'vision': {'min': 0.1, 'max': 5.3, 'type': 'float', 'name': '视力'},
        'sphere': {'min': -20.0, 'max': 20.0, 'type': 'float', 'name': '球镜(D)'},
        'cylinder': {'min': -10.0, 'max': 10.0, 'type': 'float', 'name': '柱镜(D)'},
        'axis': {'min': 0, 'max': 180, 'type': 'float', 'name': '轴位(度)'},
        'keratometry': {'min': 35.0, 'max': 50.0, 'type': 'float', 'name': '角膜曲率(D)'},
        'axial_length': {'min': 18.0, 'max': 30.0, 'type': 'float', 'name': '眼轴长度(mm)'},
        'anterior_depth': {'min': 2.0, 'max': 5.0, 'type': 'float', 'name': '前房深度(mm)'}
    },
    
    # 新增：布尔字段映射配置
    "BOOLEAN_FIELDS_MAPPING": {
        # 矫正方式字段
        'frame_glasses': '框架眼镜',
        'contact_lenses': '隐形眼镜', 
        'night_orthokeratology': '夜戴角膜塑形镜',
        
        
        # 其他布尔字段
        'premature': '是否早产',
        'is_imported': '是否导入数据',
        'is_baseline': '是否基线数据'
    },
    
    # ==================== 视力历史记录表头配置 ====================
    "VISION_HISTORY_FIELDS": [
        # 按用户要求的顺序定义字段列表，使用全局唯一配置中的display_name
        'measure_date',        # 检查时间（使用 "测量日期" display_name）
        'measure_location',    # 检查地点
        'measure_type',        # 检查性质（使用 "检查类型" display_name）
        'left_eye_naked',      # 左眼裸眼视力
        'right_eye_naked',     # 右眼裸眼视力
        'left_vision_level',   # 左眼视力等级
        'right_vision_level',  # 右眼视力等级
        'left_se',             # 左眼等效球镜（使用 "左眼等效球镜度" display_name）
        'right_se',            # 右眼等效球镜（使用 "右眼等效球镜度" display_name）
        'actions'              # 操作列（详情、删除、日志按钮）
    ],

    # ==================== 随访历史记录表头配置 ====================
    "FOLLOWUP_HISTORY_FIELDS": [
        # 按业务需求定义随访记录历史表格字段列表，使用全局唯一配置中的display_name
        'followup_date',              # 随访日期
        'interviewer',                # 随访员
        'interviewee',                # 被访者
        'interviewee_relation',       # 关系
        'contact_method',             # 联系方式
        'followup_type',              # 随访类型
        'intervention_satisfaction',   # 干预满意度
        'intervention_effect_evaluation', # 干预效果评价
        'vision_change_perception',   # 视力变化感知
        'actions'                     # 操作列（详情、删除、日志按钮）
    ],

    # 📊 视力计算配置
    # 说明：基于技术文档B-3.2节的SE值计算和判定标准
    # 用途：统一SE计算逻辑，替代硬编码的计算方式
    "VISION_CALCULATION_CONFIG": {
        "se_calculation": {
            "formula": "sphere + cylinder / 2",     # SE计算公式
            "rounding_digits": 2,                   # 保留小数位数
            "null_handling": "return_none"          # 空值处理方式
        },
        "recalculation_triggers": {
            "sphere_change": True,                  # 球镜变化时重新计算
            "cylinder_change": True,                # 柱镜变化时重新计算
            "force_recalculate": False              # 是否强制重新计算
        }
    },

    # 📊 视力等级判定配置
    # 说明：基于技术文档B-3.2.2节的视力分级算法业务标准
    # 用途：替代vision_calculation.py中的硬编码判定逻辑
    "VISION_LEVEL_THRESHOLDS": {
        "高度近视": {"se_max": -6.00},
        "中度近视": {"se_max": -3.00, "se_min": -6.00},
        "轻度近视": {"se_max": -0.50, "se_min": -3.00},
        "临床前期近视": {
            "age_groups": {
                "6-9": {"se_max": 1.25, "se_min": -0.50},
                "10-12": {"se_max": 0.75, "se_min": -0.50}
            }
        },
        "假性近视": {"dilated_se_threshold": 0.01},
        "正常": {"default": True}
    },

    # 📊 效果评估阈值配置
    # 说明：基于技术文档B-3.2.2节的基线对比业务标准
    # 用途：配置化效果评估阈值，支持动态调整判定标准
    "EFFECT_ASSESSMENT_THRESHOLDS": {
        "vision_change": {"improve": 0.1, "decline": -0.1},        # 视力变化阈值（视力表最小分度值）
        "se_change": {"improve": 0.25, "decline": -0.25},          # SE变化阈值（临床最小有意义差异）
        "sphere_change": {"improve": 0.25, "decline": -0.25},      # 球镜变化阈值
        "cylinder_change": {"significant": 0.25},                  # 散光变化阈值
        "axis_change": {"significant": 5}                          # 轴位变化阈值（轴位测量误差范围）
    },

    # ==================== 视力模块导出配置（由ConfigManager动态生成） ====================
    # 注意：VISION_EXPORT_CONFIG现在由ConfigManager.get_vision_export_config()动态构建
    # 配置从ALL_FIELD_CONFIG_REGISTRY的vision_record表字段自动生成
    "VISION_EXPORT_CONFIG": {
        "excel": {
            "columns": [
                {"field": "measure_date", "display_name": "检查日期"},
                {"field": "measure_location", "display_name": "检查地点（机构）"},
                {"field": "left_eye_naked", "display_name": "左眼裸眼视力"},
                {"field": "right_eye_naked", "display_name": "右眼裸眼视力"},
                {"field": "left_se", "display_name": "左眼等效球镜"},
                {"field": "right_se", "display_name": "右眼等效球镜"},
                {"field": "comprehensive_vision_level", "display_name": "视力等级"}
            ],
            "date_format": "%Y-%m-%d",
            "filename_template": "{student_name}_{education_id}_视力记录.xlsx"
        },
        "pdf": {
            "title": "视力检查报告",
            "header": {
                "hospital_name": "学生视力健康检查中心",
                "department": "眼科检查科",
                "logo_path": None
            },
            "footer": {
                "signature_line": "检查医师签名：_______________",
                "date_line": "报告日期：_______________",
                "hospital_seal": "医院印章"
            },
            "patient_info_fields": [
                {"field": "education_id", "display_name": "教育ID号码"},
                {"field": "name", "display_name": "姓名"},
                {"field": "gender", "display_name": "性别"},
                {"field": "age", "display_name": "年龄"},
                {"field": "birthday", "display_name": "出生日期"},
                {"field": "school", "display_name": "学校"},
                {"field": "class_name", "display_name": "班级"},
                {"field": "phone", "display_name": "联系电话"}
            ],
            "exam_info_fields": [
                {"field": "measure_date", "display_name": "检查日期"},
                {"field": "measure_time", "display_name": "检查时间"},
                {"field": "measure_location", "display_name": "检查地点"},
                {"field": "measurer", "display_name": "检查医师"},
                {"field": "equipment_model", "display_name": "检查设备"},
                {"field": "measure_type", "display_name": "检查类型"}
            ],
            "vision_data_sections": [
                {
                    "section": "裸眼视力",
                    "fields": [
                        {"field": "right_eye_naked", "display_name": "右眼裸眼视力"},
                        {"field": "left_eye_naked", "display_name": "左眼裸眼视力"}
                    ]
                },
                {
                    "section": "矫正视力",
                    "fields": [
                        {"field": "right_eye_corrected", "display_name": "右眼矫正视力"},
                        {"field": "left_eye_corrected", "display_name": "左眼矫正视力"}
                    ]
                },
                {
                    "section": "屈光检查",
                    "fields": [
                        {"field": "right_sphere", "display_name": "右眼球镜度数"},
                        {"field": "left_sphere", "display_name": "左眼球镜度数"},
                        {"field": "right_cylinder", "display_name": "右眼柱镜度数"},
                        {"field": "left_cylinder", "display_name": "左眼柱镜度数"},
                        {"field": "right_axis", "display_name": "右眼轴位"},
                        {"field": "left_axis", "display_name": "左眼轴位"},
                        {"field": "right_se", "display_name": "右眼等效球镜"},
                        {"field": "left_se", "display_name": "左眼等效球镜"}
                    ]
                },
                {
                    "section": "散瞳验光",
                    "fields": [
                        {"field": "right_dilated_sphere", "display_name": "右眼散瞳球镜"},
                        {"field": "left_dilated_sphere", "display_name": "左眼散瞳球镜"},
                        {"field": "right_dilated_cylinder", "display_name": "右眼散瞳柱镜"},
                        {"field": "left_dilated_cylinder", "display_name": "左眼散瞳柱镜"},
                        {"field": "right_dilated_axis", "display_name": "右眼散瞳轴位"},
                        {"field": "left_dilated_axis", "display_name": "左眼散瞳轴位"}
                    ]
                },
                {
                    "section": "生物测量",
                    "fields": [
                        {"field": "right_axial_length", "display_name": "右眼眼轴长度"},
                        {"field": "left_axial_length", "display_name": "左眼眼轴长度"},
                        {"field": "right_anterior_depth", "display_name": "右眼前房深度"},
                        {"field": "left_anterior_depth", "display_name": "左眼前房深度"},
                        {"field": "right_keratometry_K1", "display_name": "右眼K1值"},
                        {"field": "left_keratometry_K1", "display_name": "左眼K1值"},
                        {"field": "right_keratometry_K2", "display_name": "右眼K2值"},
                        {"field": "left_keratometry_K2", "display_name": "左眼K2值"}
                    ]
                }
            ],
            "conclusion_fields": [
                {"field": "comprehensive_vision_level", "display_name": "视力等级"},
                {"field": "vision_level", "display_name": "视力分级"},
                {"field": "eye_fatigue", "display_name": "眼疲劳情况"},
                {"field": "other_info", "display_name": "其他信息"},
                {"field": "remarks", "display_name": "备注"}
            ],
            "filename_template": "{student_name}_{education_id}_视力检查报告.pdf"
        }
    },

    # ==================== 视力模块API配置 ====================
    "VISION_API_CONFIG": {
        # ✅ 补充：前端架构必需的API端点配置
        "api_endpoints": {
            "create": "/api/vision_records",
            "update": "/api/vision_records",
            "delete": "/api/vision_records",
            "list": "/api/vision_records/list",
            "logs": "/api/vision_records/logs",
            "logs_all": "/api/vision_records/logs/all"
        },
        "validation": {
            "required_fields": {
                "create": {
                    "student_id": "学生ID不能为空",
                    "measure_date": "测量日期不能为空", 
                    "measurer": "检查人员不能为空"
                },
                "update": {
                    "measurer": "检查人员不能为空"
                }
            },
            "field_types": {
                "measure_date": "date",
                "measure_time": "time",
                "right_eye_naked": "float",
                "left_eye_naked": "float",
                "right_sphere": "float",
                "left_sphere": "float"
            }
        },
        "defaults": {
            "measure_type": "常规检查",
            "is_baseline": False,
            "data_year": "auto_calculate"
        },
        "messages": {
            "create_success": "视力记录创建成功",
            "update_success": "视力记录更新成功",
            "delete_success": "视力记录删除成功",
            "not_found": "视力记录不存在",
            "validation_error": "数据验证失败"
        },
        "pagination": {
            "default_per_page": 10,
            "max_per_page": 100
        }
    },

    # ==================== 视力历史记录表头配置（静态配置） ====================
    "VISION_HISTORY_TABLE_CONFIG": {
        # 🔧 用户要求的表头字段配置（引用全局唯一字段定义，避免重复）
        "field_sequence": [
            # 表头字段顺序：检查时间、检查地点、检查性质、左眼裸眼视力、右眼裸眼视力、
            # 左眼视力等级、右眼视力等级、左眼等效球镜、右眼等效球镜
            "measure_date",        # 检查时间（只显示日期）
            "measure_location",    # 检查地点
            "measure_type",        # 检查性质
            "left_eye_naked",      # 左眼裸眼视力
            "right_eye_naked",     # 右眼裸眼视力
            "left_vision_level",   # 左眼视力等级
            "right_vision_level",  # 右眼视力等级
            "left_se",             # 左眼等效球镜
            "right_se"             # 右眼等效球镜
        ],
        # 🔧 自定义表头显示名映射（覆盖默认display_name）
        "custom_header_mapping": {
            "measure_date": "检查时间",
            "measure_location": "检查地点", 
            "measure_type": "检查性质",
            "left_eye_naked": "左眼裸眼视力",
            "right_eye_naked": "右眼裸眼视力",
            "left_vision_level": "左眼视力等级",
            "right_vision_level": "右眼视力等级",
            "left_se": "左眼等效球镜",
            "right_se": "右眼等效球镜"
        }
    },

    # ==================== 视力前端配置（由ConfigManager动态生成） ====================
    # 注意：VISION_FRONTEND_CONFIG现在由ConfigManager动态构建
    # 配置从GLOBAL_OPTIONS_CONFIG和ALL_FIELD_CONFIG_REGISTRY自动生成
    "VISION_FRONTEND_CONFIG": {},  # 保留空配置以避免兼容性问题
}

# =================================================================
# 干预管理配置（在CONFIG_REGISTRY之前定义）
# =================================================================

# 干预方式选项
INTERVENTION_TYPE_OPTIONS = [
    "耳穴压丸", "刮痧", "艾灸", "中药熏蒸", "热灸训练", "热磁脉冲", "拔罐"
]

# 操作地点选项
OPERATION_LOCATION_OPTIONS = [
    "曲线社区卫生服务中心", "家庭", "学校", "其他"
]

# 按压强度选项
PRESS_STRENGTH_OPTIONS = ["轻度", "中度", "重度"]

# 配合程度选项
COOPERATION_LEVEL_OPTIONS = ["良好", "一般", "较差"]

# 即时效果选项
IMMEDIATE_EFFECT_OPTIONS = ["有效", "无效", "待观察"]

# 家长关系选项
HOME_OPERATOR_RELATION_OPTIONS = [
    "父亲", "母亲", "爷爷", "奶奶", "外公", "外婆", "其他"
]

# 患者反应选项
PATIENT_REACTION_OPTIONS = ["舒适", "热感", "轻微疼痛", "其他"]

# =================================================================
# 干预方式专用配置
# =================================================================

# 耳穴压丸专用配置
ERXUE_YAWAN_CONFIG = {
    "display_name": "耳穴压丸",
    "operation_tools": ["手动粘贴"],
    "consumed_materials": ["王不留行籽", "磁珠"],
    "operation_sites": ["左耳", "右耳", "双耳"],
    "acupoints": ["眼", "肝", "肾", "脾", "心", "神门", "枕", "目1", "目2"],
    "press_methods": ["耳部穴位粘贴"],
    "press_strength": PRESS_STRENGTH_OPTIONS,
    "press_frequency": 30,                    # 按压频率
    "is_imported": True,
    "import_source": "Excel导入",
    # 新增字段配置
    "operation_tools": ["耳穴贴", "镊子", "消毒棉签", "放大镜", "酒精棉球"],
    "consumed_materials": ["王不留行籽", "胶布", "医用酒精", "棉签", "磁珠"],
    "operation_sites": ["双耳", "左耳", "右耳", "耳尖", "耳垂"]
}

# 刮痧专用配置
GUASHA_CONFIG = {
    "display_name": "刮痧",
    "operation_tools": ["刮痧板", "牛角板", "玉石板"],
    "consumed_materials": ["刮痧油", "润滑膏"],
    "operation_sites": ["颈部", "背部", "面部", "四肢"],
    "press_strength": PRESS_STRENGTH_OPTIONS,
    "home_intervention_support": False,
    "duration_range": [10, 30],
    # 新增字段配置
    "operation_tools": ["刮痧板(牛角)", "刮痧板(玉石)", "刮痧板(水牛角)", "毛巾", "温水"],
    "consumed_materials": ["刮痧油", "消毒液", "纸巾", "润肤乳", "清洁毛巾"],
    "operation_sites": ["颈部", "背部", "肩部", "四肢", "头部", "面部"]
}

# 艾灸专用配置
AIGIU_CONFIG = {
    "display_name": "艾灸",
    "operation_tools": ["艾条", "艾灸盒", "温针灸"],
    "consumed_materials": ["艾条", "艾绒"],
    "operation_sites": ["面部穴位", "手部穴位", "背部穴位"],
    "temperature_range": [40, 50],
    "home_intervention_support": False,
    "duration_range": [15, 45],
    # 新增字段配置
    "operation_tools": ["艾条", "艾灸盒", "艾灸架", "打火机", "镊子", "温度计"],
    "consumed_materials": ["艾条", "艾绒", "胶布", "防烫垫", "湿毛巾", "清洁用品"],
    "operation_sites": ["百会穴", "太阳穴", "风池穴", "肩井穴", "背部穴位", "四肢穴位"]
}

# 中药熏蒸专用配置
ZHONGYAO_XUNZHENG_CONFIG = {
    "display_name": "中药熏蒸",
    "operation_tools": ["熏蒸仪", "蒸汽机"],
    "consumed_materials": ["中药包", "熏蒸液"],
    "operation_sites": ["眼部", "面部", "全身"],
    "temperature_range": [35, 45],
    "home_intervention_support": False,
    "duration_range": [20, 40],
    # 新增字段配置
    "operation_tools": ["熏蒸仪", "熏蒸头罩", "温度计", "计时器", "毛巾", "防护用品"],
    "consumed_materials": ["中药包", "蒸馏水", "防护用品", "清洁用品", "消毒用品"],
    "operation_sites": ["眼部", "面部", "头部", "全身熏蒸"]
}

# 热灸训练专用配置
REJIU_TRAINING_CONFIG = {
    "display_name": "热灸训练",
    "operation_tools": ["热灸仪", "红外线灯"],
    "consumed_materials": ["治疗垫", "导热膏"],
    "operation_sites": ["眼周", "颈部", "手部"],
    "intensity_levels": ["1档", "2档", "3档", "4档", "5档"],
    "home_intervention_support": False,
    "duration_range": [15, 30],
    # 新增字段配置
    "operation_tools": ["热灸仪", "温度探头", "定时器", "护目镜", "调节器", "支架"],
    "consumed_materials": ["电力消耗", "清洁用品", "护理用品", "防护用品", "消毒用品"],
    "operation_sites": ["眼周穴位", "太阳穴", "百会穴", "风池穴", "四白穴"]
}

# 热磁脉冲专用配置
RECI_PULSE_CONFIG = {
    "display_name": "热磁脉冲",
    "operation_tools": ["热磁脉冲仪", "电极片"],
    "consumed_materials": ["导电膏", "电极片"],
    "operation_sites": ["眼周穴位", "颈部穴位", "手部穴位"],
    "pulse_levels": ["1档", "2档", "3档", "4档", "5档"],
    "frequency_range": [10, 50],
    "home_intervention_support": False,
    "duration_range": [10, 25],
    # 新增字段配置
    "operation_tools": ["热磁脉冲仪", "磁疗头", "温控器", "强度调节器", "定时器", "支架"],
    "consumed_materials": ["电力消耗", "导电膏", "清洁用品", "消毒用品", "护理用品"],
    "operation_sites": ["眼部穴位", "头部穴位", "颈部穴位", "肩部穴位"]
}

# 拔罐专用配置
BAOGUAN_CONFIG = {
    "display_name": "拔罐",
    "operation_tools": ["玻璃罐", "竹罐", "硅胶罐"],
    "consumed_materials": ["拔罐油", "酒精"],
    "operation_sites": ["背部", "颈部", "四肢"],
    "suction_strength": PRESS_STRENGTH_OPTIONS,
    "home_intervention_support": False,
    "duration_range": [5, 15],
    # 新增字段配置
    "operation_tools": ["玻璃罐", "塑料罐", "抽气罐", "酒精", "棉球", "打火机"],
    "consumed_materials": ["医用酒精", "棉球", "消毒液", "润肤油", "清洁用品"],
    "operation_sites": ["背部", "肩部", "腰部", "腿部", "胸部"]
}

# 在BAOGUAN_CONFIG定义后添加统一配置结构
# 统一差异化配置结构（基于现有专用配置整合）
INTERVENTION_SPECIFIC_OPTIONS = {
    "耳穴压丸": {
        "operation_tools": ["耳穴贴", "镊子", "消毒棉签", "放大镜", "酒精棉球"],
        "consumed_materials": ["王不留行籽", "胶布", "医用酒精", "棉签", "磁珠"],
        "operation_sites": ["双耳", "左耳", "右耳", "耳尖", "耳垂"]
    },
    "刮痧": {
        "operation_tools": ["刮痧板(牛角)", "刮痧板(玉石)", "刮痧板(水牛角)", "毛巾", "温水"],
        "consumed_materials": ["刮痧油", "消毒液", "纸巾", "润肤乳", "清洁毛巾"],
        "operation_sites": ["颈部", "背部", "肩部", "四肢", "头部", "面部"]
    },
    "艾灸": {
        "operation_tools": ["艾条", "艾灸盒", "艾灸架", "打火机", "镊子", "温度计"],
        "consumed_materials": ["艾条", "艾绒", "胶布", "防烫垫", "湿毛巾", "清洁用品"],
        "operation_sites": ["百会穴", "太阳穴", "风池穴", "肩井穴", "背部穴位", "四肢穴位"]
    },
    "拔罐": {
        "operation_tools": ["玻璃罐", "塑料罐", "抽气罐", "酒精", "棉球", "打火机"],
        "consumed_materials": ["医用酒精", "棉球", "消毒液", "润肤油", "清洁用品"],
        "operation_sites": ["背部", "肩部", "腰部", "腿部", "胸部"]
    },
    "中药熏蒸": {
        "operation_tools": ["熏蒸仪", "熏蒸头罩", "温度计", "计时器", "毛巾", "防护用品"],
        "consumed_materials": ["中药包", "蒸馏水", "防护用品", "清洁用品", "消毒用品"],
        "operation_sites": ["眼部", "面部", "头部", "全身熏蒸"]
    },
    "热灸训练": {
        "operation_tools": ["热灸仪", "温度探头", "定时器", "护目镜", "调节器", "支架"],
        "consumed_materials": ["电力消耗", "清洁用品", "护理用品", "防护用品", "消毒用品"],
        "operation_sites": ["眼周穴位", "太阳穴", "百会穴", "风池穴", "四白穴"]
    },
    "热磁脉冲": {
        "operation_tools": ["热磁脉冲仪", "磁疗头", "温控器", "强度调节器", "定时器", "支架"],
        "consumed_materials": ["电力消耗", "导电膏", "清洁用品", "消毒用品", "护理用品"],
        "operation_sites": ["眼部穴位", "头部穴位", "颈部穴位", "肩部穴位"]
    }
}

# 创建统一的INTERVENTION_CONFIG配置（满足前端期望结构）
INTERVENTION_CONFIG = {
    "intervention_types": INTERVENTION_TYPE_OPTIONS,
    "select_options": {
        "press_strength": PRESS_STRENGTH_OPTIONS,
        "cooperation_level": COOPERATION_LEVEL_OPTIONS,
        "operation_location": OPERATION_LOCATION_OPTIONS,
        "immediate_effect": IMMEDIATE_EFFECT_OPTIONS,
        "home_operator_relation": HOME_OPERATOR_RELATION_OPTIONS
    },
    "multi_select_options": {
        "acupoints": ERXUE_YAWAN_CONFIG["acupoints"],
        "press_methods": ERXUE_YAWAN_CONFIG["press_methods"],
        "patient_reaction": PATIENT_REACTION_OPTIONS
    },
    "intervention_specific_options": INTERVENTION_SPECIFIC_OPTIONS
}

# 在CONFIG_REGISTRY注册中补充新配置：
CONFIG_REGISTRY.update({
    # ...existing config registrations...
    
    
    # 新增统一配置注册
    "INTERVENTION_TYPE_OPTIONS": INTERVENTION_TYPE_OPTIONS,
    "PRESS_STRENGTH_OPTIONS": PRESS_STRENGTH_OPTIONS,
    "COOPERATION_LEVEL_OPTIONS": COOPERATION_LEVEL_OPTIONS,
    "IMMEDIATE_EFFECT_OPTIONS": IMMEDIATE_EFFECT_OPTIONS,
    "HOME_OPERATOR_RELATION_OPTIONS": HOME_OPERATOR_RELATION_OPTIONS,
    "OPERATION_LOCATION_OPTIONS": OPERATION_LOCATION_OPTIONS,
    "PATIENT_REACTION_OPTIONS": PATIENT_REACTION_OPTIONS,
    "ERXUE_YAWAN_CONFIG": ERXUE_YAWAN_CONFIG,
    "INTERVENTION_SPECIFIC_OPTIONS": INTERVENTION_SPECIFIC_OPTIONS,
    "INTERVENTION_CONFIG": INTERVENTION_CONFIG
})

# 🔧 新增：干预方式配置映射表（前端JavaScript期望的结构）
INTERVENTION_TYPE_CONFIG_MAP = {
    "耳穴压丸": {
        "display_name": "耳穴压丸",
        "specific_fields": {
            "acupoints": {
                "display_name": "穴位选择",
                "field_type": "multi_checkbox",
                "options": ["眼", "肝", "肾", "脾", "心", "神门", "枕", "目1", "目2"]
            },
            "press_methods": {
                "display_name": "贴压方式",
                "field_type": "multi_checkbox",
                "options": ["耳部穴位粘贴"]
            },
            "press_strength": {
                "display_name": "按压强度",
                "field_type": "select",
                "options": ["轻度", "中度", "重度"]
            },
            "press_frequency": {
                "display_name": "按压频率(次/分钟)",
                "field_type": "number_input",
                "range": [30, 120],
                "unit": "次/分钟"
            }
        }
    },
    "刮痧": {
        "display_name": "刮痧",
        "specific_fields": {
            "scraping_intensity": {
                "display_name": "刮痧强度",
                "field_type": "select",
                "options": ["轻刮", "中刮", "重刮"]
            },
            "scraping_direction": {
                "display_name": "刮痧方向",
                "field_type": "select",
                "options": ["由上到下", "由内到外", "顺时针", "逆时针"]
            }
        }
    },
    "艾灸": {
        "display_name": "艾灸",
        "specific_fields": {
            "moxibustion_type": {
                "display_name": "艾灸类型",
                "field_type": "select",
                "options": ["悬灸", "隔物灸", "直接灸", "温针灸"]
            },
            "temperature_level": {
                "display_name": "温度等级",
                "field_type": "select",
                "options": ["温和", "温热", "较热"]
            }
        }
    },
    "中药熏蒸": {
        "display_name": "中药熏蒸",
        "specific_fields": {
            "steam_temperature": {
                "display_name": "熏蒸温度(℃)",
                "field_type": "number_input",
                "range": [35, 45],
                "unit": "℃"
            },
            "medicine_formula": {
                "display_name": "药物配方",
                "field_type": "select",
                "options": ["明目1号", "明目2号", "清热明目方", "滋阴明目方"]
            }
        }
    },
    "热灸训练": {
        "display_name": "热灸训练",
        "specific_fields": {
            "intensity_level": {
                "display_name": "强度档位",
                "field_type": "select",
                "options": ["1档", "2档", "3档", "4档", "5档"]
            },
            "treatment_mode": {
                "display_name": "治疗模式",
                "field_type": "select",
                "options": ["持续模式", "间歇模式", "渐进模式"]
            }
        }
    },
    "热磁脉冲": {
        "display_name": "热磁脉冲",
        "specific_fields": {
            "pulse_frequency": {
                "display_name": "脉冲频率(Hz)",
                "field_type": "number_input",
                "range": [10, 50],
                "unit": "Hz"
            },
            "magnetic_intensity": {
                "display_name": "磁场强度档位",
                "field_type": "select",
                "options": ["1档", "2档", "3档", "4档", "5档"]
            }
        }
    },
    "拔罐": {
        "display_name": "拔罐",
        "specific_fields": {
            "suction_strength": {
                "display_name": "负压强度",
                "field_type": "select",
                "options": ["轻度", "中度", "重度"]
            },
            "cupping_method": {
                "display_name": "拔罐方式",
                "field_type": "select",
                "options": ["留罐", "闪罐", "走罐", "刺络拔罐"]
            }
        }
    }
}

# =================================================================
# 干预模块全局唯一配置驱动架构配置
# =================================================================

# 干预查询字段配置（用于FixedQueryArea组件）
# 干预历史记录字段配置（历史表格显示）
INTERVENTION_HISTORY_FIELDS = {
    "intervention_date": {
        "display_name": "干预日期",
        "field_type": "date",
        "width": "100px",
        "order": 1
    },
    "operation_time": {
        "display_name": "操作时间", 
        "field_type": "time",
        "width": "80px",
        "order": 2
    },
    "intervention_type": {
        "display_name": "干预方式",
        "field_type": "text", 
        "width": "100px",
        "order": 3
    },
    "operator": {
        "display_name": "操作医生",
        "field_type": "text",
        "width": "80px", 
        "order": 4
    },
    "operation_location": {
        "display_name": "操作地点",
        "field_type": "text",
        "width": "100px",
        "order": 5
    },
    "cooperation_level": {
        "display_name": "配合程度", 
        "field_type": "text",
        "width": "80px",
        "order": 6
    },
    "immediate_effect": {
        "display_name": "即时效果",
        "field_type": "text", 
        "width": "80px",
        "order": 7
    },
    "actions": {
        "display_name": "操作",
        "field_type": "actions",
        "width": "150px", 
        "order": 8
    }
}

# 干预表单字段配置
INTERVENTION_FORM_FIELDS = {
    # 基础信息组
    "intervention_date": {"display_name": "干预日期", "required": True, "group": "basic"},
    "operation_time": {"display_name": "操作时间", "required": True, "group": "basic"},
    "intervention_type": {"display_name": "干预方式", "required": True, "group": "basic"},
    "operator": {"display_name": "操作医生", "required": True, "group": "basic"},
    "duration_minutes": {"display_name": "操作持续时间(分钟)", "group": "details"},
    "operation_location": {"display_name": "操作地点", "group": "details"},
    "immediate_effect": {"display_name": "即时效果", "group": "evaluation"},
    "cooperation_level": {"display_name": "配合程度", "group": "evaluation"},
    # 级联字段
    "operation_tools": {"display_name": "操作工具", "field_type": "cascading", "group": "details"},
    "consumed_materials": {"display_name": "消耗材料", "field_type": "cascading", "group": "details"},
    "operation_sites": {"display_name": "操作部位", "field_type": "cascading", "group": "details"},
    # 补充字段
    "patient_reaction": {"display_name": "患者反应", "group": "notes"},
    "details": {"display_name": "操作记录/补充说明", "group": "notes"}
}

# 干预导出字段配置
INTERVENTION_EXPORT_FIELDS = [
    "intervention_date", "operation_time", "intervention_type", "operator",
    "duration_minutes", "operation_location", "operation_tools", 
    "consumed_materials", "operation_sites", "acupoints", "press_methods",
    "press_strength", "press_frequency", "immediate_effect", 
    "cooperation_level", "patient_reaction", "details"
]

# 干预API配置（统一消息、验证、分页等）
INTERVENTION_API_CONFIG = {
    # 验证消息
    "validation_messages": {
        "required_fields": "以下字段为必填项：干预日期、操作时间、干预方式、操作医生",
        "invalid_date": "干预日期格式不正确",
        "invalid_time": "操作时间格式不正确", 
        "invalid_type": "干预方式不在允许范围内",
        "invalid_duration": "操作持续时间必须是正整数"
    },
    # 成功消息
    "success_messages": {
        "create": "干预记录创建成功",
        "update": "干预记录更新成功", 
        "delete": "干预记录删除成功",
        "restore": "干预记录恢复成功"
    },
    # 错误消息
    "error_messages": {
        "not_found": "干预记录不存在",
        "student_not_found": "学生信息不存在",
        "create_failed": "干预记录创建失败",
        "update_failed": "干预记录更新失败",
        "delete_failed": "干预记录删除失败"
    },
    # 分页默认值
    "pagination": {
        "default_page": 1,
        "default_per_page": 100,
        "max_per_page": 1000
    },
    # 导出配置
    "export": {
        "array_separator": "、",
        "default_format": "xlsx",
        "max_records": 10000
    }
}

# ==================== 干预模块查询字段构建函数 ====================
# 在CONFIG_REGISTRY中注册新配置
CONFIG_REGISTRY.update({
    # 干预模块配置 - 基础配置
    "INTERVENTION_HISTORY_FIELDS": INTERVENTION_HISTORY_FIELDS,
    "INTERVENTION_FORM_FIELDS": INTERVENTION_FORM_FIELDS,
    "INTERVENTION_EXPORT_FIELDS": INTERVENTION_EXPORT_FIELDS,
    "INTERVENTION_API_CONFIG": INTERVENTION_API_CONFIG,
    "INTERVENTION_TYPE_CONFIG_MAP": INTERVENTION_TYPE_CONFIG_MAP
})

# 🔧 新增：统一日志服务配置
UNIFIED_LOG_CONFIG = {
    "module_field_mappings": {
        # VisionRecord关键字段（业务核心数据，排除系统字段和计算字段）
        "VisionRecord": [
            # 视力数据字段（用户录入的核心测量数据）
            'right_eye_naked', 'left_eye_naked', 'right_eye_corrected', 'left_eye_corrected', 
            'right_sphere', 'left_sphere', 'right_cylinder', 'left_cylinder',
            'right_axis', 'left_axis',
            # 检查信息字段（影响数据质量的关键信息）
            'measure_date', 'measure_time', 'measure_location', 'measure_type', 'measurer',
            # 其他重要字段（用户关心的补充信息）
            'remarks', 'equipment_model', 'eye_fatigue', 'other_info',
            # 散瞳数据字段（专业验光的重要数据）
            'right_dilated_sphere', 'left_dilated_sphere', 'right_dilated_cylinder', 'left_dilated_cylinder',
            'right_dilated_axis', 'left_dilated_axis', 'right_dilated_vision', 'left_dilated_vision',
            # 角膜曲率和眼轴长度（生物测量的关键参数）
            'right_keratometry_K1', 'left_keratometry_K1', 'right_keratometry_K2', 'left_keratometry_K2',
            'right_axial_length', 'left_axial_length', 'right_anterior_depth', 'left_anterior_depth'
        ],
        # InterventionRecord关键字段（干预操作的核心业务数据）
        "InterventionRecord": [
            # 基础信息字段（干预操作的核心标识信息）
            'intervention_date', 'operation_time', 'intervention_type', 'operator', 'duration_minutes',
            # 操作详情字段（具体操作内容，JSON多选字段）
            'operation_location', 'operation_tools', 'consumed_materials', 'operation_sites',
            # 耳穴压丸专用字段（最复杂干预方式的专业参数）
            'acupoints', 'press_methods', 'press_strength', 'press_frequency',
            # 效果评估字段（干预效果的关键评价）
            'immediate_effect', 'cooperation_level', 'patient_reaction',
            # 家庭干预字段（家庭干预的特有业务数据）
            'is_home_intervention', 'home_operator', 'home_operator_relation',
            # 操作记录字段（用户补充的重要信息）
            'details', 'student_feedback'
        ],
        # FollowupRecord关键字段（随访记录的核心业务数据）
        "FollowupRecord": [
            # 基础信息字段（随访的核心标识信息）
            'followup_date', 'followup_time', 'followup_type', 'contact_method',
            # 人员信息字段（随访涉及的关键人员）
            'interviewer', 'interviewee', 'interviewee_relation',
            # 随访内容字段（随访的具体业务内容）
            'followup_content', 'vision_change_perception', 'intervention_compliance',
            # 效果评估字段（随访效果的关键评价）
            'intervention_satisfaction', 'intervention_effect_evaluation',
            # 计划安排字段（后续跟进的重要信息）
            'next_followup_plan', 'followup_result'
        ],
        # User关键字段（系统管理模块）
        "User": [
            'username', 'real_name', 'mobile', 'email', 'gender', 'department', 'position', 'status', 'remark', 'roles'
        ],
        # Role关键字段（系统管理模块）
        "Role": [
            'name', 'description', 'status'
        ],
        # Permission关键字段（系统管理模块）
        "Permission": [
            'code', 'name', 'description', 'module', 'action', 'status'
        ]
    },
    
    # 日志操作类型配置
    "action_types": {
        "CREATE": {"label": "创建", "color": "success", "icon": "plus"},
        "UPDATE": {"label": "修改", "color": "warning", "icon": "edit"},
        "DELETE": {"label": "删除", "color": "danger", "icon": "trash"},
        "RESTORE": {"label": "恢复", "color": "info", "icon": "restore"}
    },
    
    # 显示格式配置
    "display_formats": {
        "time_format": "%Y-%m-%d %H:%M:%S",
        "date_format": "%Y-%m-%d"
    }
}

# 确保在CONFIG_REGISTRY中注册日志配置
CONFIG_REGISTRY.update({
    # ...existing config...
    
    # 日志配置注册（确保存在）
    "UNIFIED_LOG_CONFIG": UNIFIED_LOG_CONFIG
})

# 动态加载配置项（确保存在）
def load_config(config_name):
    """从环境变量获取配置文件路径并读取配置"""
    # config_path建议通过业务层传递，禁止直接os.getenv
    config_path = "config.json"
    
    # 读取配置文件
    with open(config_path, "r", encoding="utf-8") as f:
        config_data = json.load(f)
        
    # 返回指定的配置项
    return config_data.get(config_name)

# ==================== 统一字段映射配置（现在由ConfigManager动态生成） ====================

# 这些配置现在由ConfigManager动态生成，不再需要静态函数
# FIELD_DISPLAY_MAPPING 和 COMPLETE_FIELDS 由 ConfigManager.build_field_display_mapping() 和 ConfigManager.build_complete_fields() 提供

# 临时保留静态配置以确保向后兼容，将在验证后移除
FIELD_DISPLAY_MAPPING = {}  # 将由ConfigManager动态提供

# 完整字段列表（兼容分析模块）
# 🔧 完整字段列表配置（全局唯一配置驱动）
# 
# 📋 配置表调用关系说明：
# 
# 🔧 后端调用：
# - analysis_api.py:第124行 - 配置加载，用于扩展METRIC_CONFIG配置
# - chart_api.py:第70行 - 配置加载，用于扩展METRIC_CONFIG配置  
# - report_api.py:第40行 - 配置加载，用于扩展METRIC_CONFIG配置
# - config_manager.py:build_complete_fields() - 动态生成此配置
# 
# 📊 配置特点：
# - 动态生成：由ConfigManager.build_complete_fields()方法动态生成
# - 全局唯一：所有字段统一从ALL_FIELD_CONFIG_REGISTRY获取
# - 自动更新：基于全局字段配置自动生成，无需手动维护
# - 优先级顺序：student_extensions → students → vision_records → intervention_records → followup_records
# 
# ⚠️ 重要变更：
# - 删除静态硬编码配置，完全使用动态生成
# - 所有模块应通过config_manager.get_config("COMPLETE_FIELDS")获取
# - 确保配置驱动架构的一致性，避免重复定义

# 🔧 字段显示名映射配置（全局唯一配置驱动）
# 
# 📋 配置表调用关系说明：
# 
# 🔧 后端调用：
# - analysis_api.py:第124行 - 配置加载，第977行 - 干预方式分组标签生成
# - chart_api.py:第68行 - 配置加载
# - report_api.py:第38行 - 配置加载
# - config_manager.py:build_field_display_mapping() - 动态生成此配置
# 
# 📊 配置特点：
# - 动态生成：由ConfigManager.build_field_display_mapping()方法动态生成
# - 全局唯一：所有字段显示名统一在此配置中管理
# - 自动更新：基于ALL_FIELD_CONFIG_REGISTRY自动生成，无需手动维护
# 
# ⚠️ 重要变更：
# - 删除FIELD_LABEL_MAPPING别名，统一使用FIELD_DISPLAY_MAPPING
# - 所有模块应通过config_manager.get_config("FIELD_DISPLAY_MAPPING")获取
# - 避免硬编码引用，确保配置驱动架构的一致性

# 在CONFIG_REGISTRY中注册新配置
CONFIG_REGISTRY.update({
    # ...existing config registrations...
    
    # 🔧 统一字段映射配置注册（从全局配置自动生成）
    "FIELD_DISPLAY_MAPPING": FIELD_DISPLAY_MAPPING,
    # 🔧 修复：COMPLETE_FIELDS现在由ConfigManager动态生成，不再静态定义
})

# 🔧 新增：LOG_FRONTEND_CONFIG配置（修复系统启动失败问题）
LOG_FRONTEND_CONFIG = {
    "time_format": "%Y-%m-%d %H:%M:%S",
    "date_format": "%Y-%m-%d",
    "action_display_mapping": {
        "CREATE": {"label": "创建", "color": "success", "icon": "plus"},
        "UPDATE": {"label": "修改", "color": "warning", "icon": "edit"},
        "DELETE": {"label": "删除", "color": "danger", "icon": "trash"},
        "RESTORE": {"label": "恢复", "color": "info", "icon": "restore"}
    },
    "table_config": {
        "page_size": 20,
        "show_pagination": True,
        "show_search": True
    },
    "modal_config": {
        "auto_close": True,
        "show_backdrop": True,
        "keyboard_close": True
    }
}

# ==================== 学生档案完整管理模块配置（第10阶段配置迁移）
# 调用模块：student_complete_api.py, student_extension_service.py
# 前端调用：student_complete_record.js, student_complete_record.html
# =================================================================

# 📋 学生档案模块：基础信息字段配置
# 调用位置：student_complete_api.py create_student_complete_info(), update_student_complete_info()
# 前端调用：student_complete_record.js fillBasicForm(), student_complete_record.html 基础信息组
STUDENT_BASIC_FIELDS_CONFIG = {
    "education_id": {
        "display_name": "教育ID号",
        "field_type": "text",
        "required": True,
        "unique": True,
        "validation": r"^[A-Za-z0-9]{6,20}$",
        "placeholder": "请输入教育ID号",
        "max_length": 20,
        "form_group": "basic_info"
    },    "school": {
        "display_name": "学校",
        "field_type": "select",
        "required": False,
        "options_source": "school_options",
        "placeholder": "请选择学校",
        "form_group": "basic_info"
    },
    "class_name": {
        "display_name": "班级",
        "field_type": "select",
        "required": False,
        "options_source": "class_options",
        "placeholder": "请选择班级",
        "max_length": 10,
        "form_group": "basic_info"
    },
    "name": {
        "display_name": "姓名",
        "field_type": "text",
        "required": True,
        "validation": r"^[\u4e00-\u9fa5]{2,10}$",
        "placeholder": "请输入学生姓名",
        "max_length": 50,
        "form_group": "basic_info"
    },
    "gender": {
        "display_name": "性别",
        "field_type": "select",
        "required": False,
        "options_source": "gender_options",
        "placeholder": "请选择性别",
        "form_group": "basic_info"
    },
    "birthday": {
        "display_name": "出生日期",
        "field_type": "date",
        "required": False,
        "placeholder": "请选择出生日期",
        "form_group": "basic_info"
    },
    "phone": {
        "display_name": "联系电话",
        "field_type": "text",
        "required": False,
        "validation": r"^1[3-9]\d{9}$",
        "placeholder": "请输入11位手机号",
        "max_length": 15,
        "form_group": "basic_info"
    },
    "id_card": {
        "display_name": "身份证号码",
        "field_type": "text",
        "required": False,
        "validation": r"^\d{17}[\dXx]$",
        "placeholder": "请输入18位身份证号",
        "max_length": 18,
        "form_group": "basic_info"
    },
    "region": {
        "display_name": "所在区域",
        "field_type": "text",
        "required": False,
        "placeholder": "请输入所在区域",
        "max_length": 50,
        "form_group": "basic_info"
    },
    "contact_address": {
        "display_name": "联系地址",
        "field_type": "text",
        "required": False,
        "placeholder": "请输入详细联系地址",
        "max_length": 100,
        "form_group": "basic_info"
    },
    "parent_name": {
        "display_name": "家长姓名",
        "field_type": "text",
        "required": False,
        "placeholder": "请输入家长姓名",
        "max_length": 50,
        "form_group": "basic_info"
    },
    "parent_phone": {
        "display_name": "家长电话",
        "field_type": "text",
        "required": False,
        "validation": r"^1[3-9]\d{9}$",
        "placeholder": "请输入家长手机号",
        "max_length": 15,
        "form_group": "basic_info"
    }
}

# 📋 学生档案模块：扩展信息字段配置
# 调用位置：student_complete_api.py create_student_complete_info(), update_student_complete_info()
# 前端调用：student_complete_record.js fillBasicForm(), student_complete_record.html 健康信息组
STUDENT_EXTENSION_FIELDS_CONFIG = {
    "data_year": {
        "display_name": "数据年份",
        "field_type": "select",
        "required": True,
        "default": "2024",
        "options_source": "data_year_options",
        "placeholder": "请选择年份",
        "form_group": "health_info"
    },
    "grade": {
        "display_name": "年级",
        "field_type": "select",
        "required": False,
        "options_source": "grade_options",
        "placeholder": "请选择年级",
        "max_length": 10,
        "form_group": "health_info"
    },
    "age": {
        "display_name": "年龄",
        "field_type": "number",
        "required": False,
        "min": 3,
        "max": 18,
        "placeholder": "请输入年龄",
        "unit": "岁",
        "form_group": "health_info"
    },
    "height": {
        "display_name": "身高",
        "field_type": "number",
        "required": False,
        "min": 80,
        "max": 200,
        "step": 0.1,
        "placeholder": "请输入身高",
        "unit": "cm",
        "form_group": "health_info"
    },
    "weight": {
        "display_name": "体重",
        "field_type": "number",
        "required": False,
        "min": 10,
        "max": 100,
        "step": 0.1,
        "placeholder": "请输入体重",
        "unit": "kg",
        "form_group": "health_info"
    },
    "diet_preference": {
        "display_name": "饮食偏好",
        "field_type": "text",
        "required": False,
        "placeholder": "请输入饮食偏好",
        "max_length": 50,
        "form_group": "health_info"
    },
    "exercise_preference": {
        "display_name": "运动偏好",
        "field_type": "text",
        "required": False,
        "placeholder": "请输入运动偏好",
        "max_length": 50,
        "form_group": "health_info"
    },
    "health_education": {
        "display_name": "健康教育情况",
        "field_type": "textarea",
        "required": False,
        "placeholder": "请输入健康教育情况",
        "max_length": 200,
        "rows": 2,
        "form_group": "health_info"
    },
    "past_history": {
        "display_name": "既往史",
        "field_type": "textarea",
        "required": False,
        "placeholder": "请输入既往病史",
        "max_length": 200,
        "rows": 2,
        "form_group": "health_info"
    },
    "family_history": {
        "display_name": "家族史",
        "field_type": "textarea",
        "required": False,
        "placeholder": "请输入家族病史",
        "max_length": 200,
        "rows": 2,
        "form_group": "health_info"
    },
    "premature": {
        "display_name": "是否早产",
        "field_type": "select",
        "required": False,
        "options_source": "premature_options",
        "placeholder": "请选择",
        "form_group": "health_info"
    },
    "allergy": {
        "display_name": "过敏史",
        "field_type": "textarea",
        "required": False,
        "placeholder": "请输入过敏史",
        "max_length": 200,
        "rows": 2,
        "form_group": "health_info"
    },
    "correction_method": {
        "display_name": "矫正方式",
        "field_type": "select",
        "required": False,
        "default": "其它",
        "options_source": "correction_method_options",
        "placeholder": "请选择矫正方式",
        "form_group": "health_info"
    }
}
# 📋 学生档案模块：查询字段配置
# 调用位置：config_api.py get_student_archive_query_fields_config()
# 前端调用：FixedQueryArea.js 学生档案查询区
# ****这个表已经没有用，真正的查询区域配置统一在config_manager.apid的配置表中
STUDENT_ARCHIVE_QUERY_FIELDS = [
    {
        "field": "name",
        "display_name": "姓名", 
        "input_type": "text",
        "placeholder": "请输入学生姓名",
        "searchable": True,
        "required": False
    },
    {
        "field": "education_id",
        "display_name": "教育ID号",
        "input_type": "text",
        "placeholder": "请输入教育ID号",
        "searchable": True,
        "required": False
    },
    {
        "field": "school",
        "display_name": "学校",
        "input_type": "select",
        "options_source": "school_options",
        "placeholder": "请选择学校",
        "searchable": True,
        "required": False
    },
    {
        "field": "grade",
        "display_name": "年级",
        "input_type": "select",
        "options_source": "grade_options",
        "placeholder": "请选择年级",
        "searchable": True,
        "required": False
    },
    {
        "field": "gender",
        "display_name": "性别",
        "input_type": "select",
        "options_source": "gender_options",
        "placeholder": "请选择性别",
        "searchable": True,
        "required": False
    },
    # {
    #     "field": "age",
    #     "display_name": "年龄",
    #     "input_type": "number",
    #     "placeholder": "请输入年龄",
    #     "searchable": True,
    #     "required": False
    # },
    # {
    #     "field": "parent_phone",
    #     "display_name": "家长电话",
    #     "input_type": "text",
    #     "placeholder": "请输入家长电话",
    #     "searchable": True,
    #     "required": False
    # }
]

# 📋 学生档案模块：查询结果字段配置
# 调用位置：config_api.py get_student_archive_result_fields()
# 前端调用：QueryResultTable.js 学生档案查询结果表
STUDENT_ARCHIVE_RESULT_FIELDS = [
    {
        "field": "name",
        "display_name": "姓名",
        "type": "text",
        "width": "100px",
        "searchable": True,
        "sortable": True
    },
    {
        "field": "education_id",
        "display_name": "教育ID号",
        "type": "text",
        "width": "120px",
        "searchable": True,
        "sortable": True
    },
    {
        "field": "school",
        "display_name": "学校",
        "type": "text",
        "width": "120px",
        "searchable": True,
        "sortable": True
    },
    {
        "field": "grade",
        "display_name": "年级",
        "type": "text",
        "width": "80px",
        "searchable": True,
        "sortable": True
    },
    {
        "field": "gender",
        "display_name": "性别",
        "type": "text",
        "width": "60px",
        "searchable": True,
        "sortable": True
    },
    {
        "field": "age",
        "display_name": "年龄",
        "type": "number",
        "width": "60px",
        "searchable": True,
        "sortable": True
    },
    {
        "field": "created_at",
        "display_name": "创建时间",
        "type": "datetime",
        "width": "120px",
        "searchable": False,
        "sortable": True
    },
    {
        "field": "updated_at",
        "display_name": "更新时间",
        "type": "datetime",
        "width": "120px",
        "searchable": False,
        "sortable": True
    },
    {
        "field": "actions",
        "display_name": "操作",
        "type": "actions",
        "width": "200px",
        "buttons": ["查看", "编辑", "删除"]
    }
]

# 📋 学生档案模块：完整配置
# 调用位置：student_complete_api.py get_student_config()
# 前端调用：student_complete_record.js loadStudentConfig()
STUDENT_ARCHIVE_COMPLETE_CONFIG = {
    "basic_fields": STUDENT_BASIC_FIELDS_CONFIG,
    "extension_fields": STUDENT_EXTENSION_FIELDS_CONFIG,
    "query_fields": STUDENT_ARCHIVE_QUERY_FIELDS,
    "result_fields": STUDENT_ARCHIVE_RESULT_FIELDS,
    "field_groups": {
    "basic_info": {
            "name": "基本信息",
            "fields": list(STUDENT_BASIC_FIELDS_CONFIG.keys()),
            "collapsible": True,
            "default_expanded": True
    },
    "health_info": {
            "name": "健康信息",
            "fields": list(STUDENT_EXTENSION_FIELDS_CONFIG.keys()),
        "collapsible": True,
            "default_expanded": False
        }
    },
    "data_validation": {
        "clean_rules": {
            "strip_whitespace": True,
            "empty_string_to_none": True,
            "numeric_conversion": True
        },
        "validation_rules": {
            "education_id": {
                "required": True,
                "pattern": r"^[A-Za-z0-9]{6,20}$",
                "message": "教育ID号必须为6-20位字母数字组合"
            },
            "name": {
                "required": True,
                "pattern": r"^[\u4e00-\u9fa5]{2,10}$",
                "message": "姓名必须为2-10位中文字符"
            }
        }
    },
    "module_integration": {
    "vision_record": {
        "base_url": "/vision_record",
        "required_params": ["student_id", "name", "education_id"],
            "optional_params": ["school", "grade", "class_name", "gender", "birthday", "parent_name"],
            "control_params": ["fromComplete=true", "auto_expand=true"]
    },
    "intervention_record": {
        "base_url": "/intervention/record",
        "required_params": ["student_id", "name", "education_id"],
            "optional_params": ["school", "grade", "class_name", "gender", "birthday", "parent_name"],
            "control_params": ["fromComplete=true", "auto_expand=true"]
    },
    "followup_record": {
        "base_url": "/phone-followup",
        "required_params": ["student_id", "name", "education_id"],
            "optional_params": ["school", "grade", "class_name", "gender", "birthday", "parent_name"],
            "control_params": ["fromComplete=true", "auto_expand=true"]
        }
    }
}

# 注册学生档案模块配置到全局配置表
CONFIG_REGISTRY["STUDENT_BASIC_FIELDS_CONFIG"] = STUDENT_BASIC_FIELDS_CONFIG
CONFIG_REGISTRY["STUDENT_EXTENSION_FIELDS_CONFIG"] = STUDENT_EXTENSION_FIELDS_CONFIG
CONFIG_REGISTRY["STUDENT_ARCHIVE_QUERY_FIELDS"] = STUDENT_ARCHIVE_QUERY_FIELDS
CONFIG_REGISTRY["STUDENT_ARCHIVE_RESULT_FIELDS"] = STUDENT_ARCHIVE_RESULT_FIELDS
CONFIG_REGISTRY["STUDENT_ARCHIVE_COMPLETE_CONFIG"] = STUDENT_ARCHIVE_COMPLETE_CONFIG

# ==================== 分析模块配置开始 ====================

# 🔧 METRIC_CONFIG现在通过ConfigManager从ALL_FIELD_CONFIG_REGISTRY动态生成
# 不再在这里静态定义，避免重复配置违背三层架构原则

# METRIC_CONFIG分析字段生成规则（仅元数据，不是具体配置）
METRIC_CONFIG_GENERATION_RULES = {
    # 基础查询字段（从student+student_extension表生成）
    "basic_query_fields": ["education_id", "school", "class_name", "name", "gender", "age", "data_year", "grade"],
    
    # 视力记录字段（从vision_record表生成）
    "vision_fields": ["left_eye_naked", "right_eye_naked", "left_eye_corrected", "right_eye_corrected", 
                     "left_sphere", "right_sphere", "left_cylinder", "right_cylinder", "left_axis", "right_axis", 
                     "left_se", "right_se", "left_dilated_sphere", "right_dilated_sphere", "left_dilated_se", "right_dilated_se",
                     "left_keratometry_K1", "right_keratometry_K1", "left_axial_length", "right_axial_length",
                     "measurement_sequence", "age_at_measure", "is_baseline"],
    
    # 虚拟计算字段（需要特殊处理）
    "virtual_calculation_fields": ["vision_level", "interv_vision_level", "comprehensive_vision_level", "myopia_degree",
                                  "baseline_left_naked_change", "baseline_right_naked_change", "baseline_left_sphere_change", 
                                  "baseline_right_sphere_change", "baseline_left_se_change", "baseline_right_se_change",
                                  "baseline_left_vision_effect", "baseline_right_vision_effect", "baseline_left_se_effect", 
                                  "baseline_right_se_effect", "baseline_left_sphere_effect", "baseline_right_sphere_effect",
                                  "baseline_left_cylinder_effect", "baseline_right_cylinder_effect", "baseline_left_axis_effect", 
                                  "baseline_right_axis_effect", "left_interv_effect", "right_interv_effect"],
    
    # 字段类型映射规则
    "field_type_mapping": {
        "select_fields": ["school", "class_name", "gender", "data_year", "grade", "vision_level", "interv_vision_level", "comprehensive_vision_level", "myopia_degree"],
        "number_range_fields": ["age", "left_eye_naked", "right_eye_naked", "left_eye_corrected", "right_eye_corrected", 
                               "left_sphere", "right_sphere", "left_cylinder", "right_cylinder", "left_axis", "right_axis", 
                               "left_se", "right_se", "measurement_sequence", "age_at_measure"],
        "text_fields": ["education_id", "name", "measurer", "other_info", "eye_fatigue", "remarks", "equipment_model"],
        "date_fields": ["measure_date"],
        "time_fields": ["measure_time"],
        "boolean_fields": ["is_baseline"],
        "multi_select_fields": ["acupoints", "press_methods", "operation_tools", "consumed_materials", "operation_sites", "patient_reaction"]
    }
}

# 图表配色配置
CHART_COLORS = {
    'METRICS': {
        '上升': '#2ecc71', '维持': '#f1c40f', '下降': '#e74c3c',
        '临床前期近视': '#3498db', '轻度近视': '#9b59b6', '中度近视': '#e67e22',
        '假性近视': '#1abc9c', '正常': '#2ecc71'
    },
    'EXTENDED': ['#1abc9c', '#2ecc71', '#3498db', '#9b59b6', '#f1c40f', '#e67e22', '#e74c3c', '#34495e']
}

# 🔧 字段显示名映射配置（全局唯一配置驱动）
# 
# 📋 配置表调用关系说明：
# 
# 🔧 后端调用：
# - analysis_api.py:第124行 - 配置加载，第977行 - 干预方式分组标签生成
# - chart_api.py:第68行 - 配置加载
# - report_api.py:第38行 - 配置加载
# - config_manager.py:build_field_display_mapping() - 动态生成此配置
# 
# 📊 配置特点：
# - 动态生成：由ConfigManager.build_field_display_mapping()方法动态生成
# - 全局唯一：所有字段显示名统一在此配置中管理
# - 自动更新：基于ALL_FIELD_CONFIG_REGISTRY自动生成，无需手动维护
# 
# ⚠️ 重要变更：
# - 删除FIELD_LABEL_MAPPING别名，统一使用FIELD_DISPLAY_MAPPING
# - 所有模块应通过config_manager.get_config("FIELD_DISPLAY_MAPPING")获取
# - 避免硬编码引用，确保配置驱动架构的一致性

# 🔧 METRIC_CONFIG现在完全通过ConfigManager动态生成，不再注册静态版本
# CONFIG_REGISTRY中不再包含METRIC_CONFIG，避免重复定义

CONFIG_REGISTRY["CHART_COLORS"] = CHART_COLORS
CONFIG_REGISTRY["METRIC_CONFIG_GENERATION_RULES"] = METRIC_CONFIG_GENERATION_RULES

# ==================== 分析模块配置结束 ====================

# ==================== 虚拟字段注册表（真正的虚拟字段） ====================
# 虚拟字段：不对应数据库实际字段，仅用于前端渲染、分组查询等功能
VIRTUAL_FIELD_REGISTRY = {
    # 主表操作按钮（仅前端渲染，不参与数据库查询）
    "actions": {
        "type": "actions",
        "display_name": "操作",
        "scope": "frontend",  # 仅前端渲染
        "description": "主表操作按钮"
    },
    # 示例：性别分组虚拟字段
    "group_by_gender": {
        "type": "group",
        "display_name": "性别分组",
        "fields": ["gender"],
        "scope": "query",
        "description": "用于分组查询或统计"
    },
    # 示例：自定义统计虚拟字段
    "custom_stat": {
        "type": "stat",
        "display_name": "自定义统计",
        "fields": ["field1", "field2"],
        "scope": "query",
        "description": "自定义统计字段"
    }
}

# ==================== 配置注册：统一配置访问管理 ====================

# 注册核心配置到CONFIG_REGISTRY（架构统一）
CONFIG_REGISTRY["ALL_FIELD_CONFIG_REGISTRY"] = ALL_FIELD_CONFIG_REGISTRY
CONFIG_REGISTRY["GLOBAL_OPTIONS_CONFIG"] = GLOBAL_OPTIONS_CONFIG
CONFIG_REGISTRY["VIRTUAL_FIELD_REGISTRY"] = VIRTUAL_FIELD_REGISTRY

# 注册干预配置
CONFIG_REGISTRY["INTERVENTION_TYPE_CONFIG_MAP"] = INTERVENTION_TYPE_CONFIG_MAP
CONFIG_REGISTRY["INTERVENTION_HISTORY_FIELDS"] = INTERVENTION_HISTORY_FIELDS
CONFIG_REGISTRY["INTERVENTION_CONFIG"] = INTERVENTION_CONFIG
CONFIG_REGISTRY["INTERVENTION_SPECIFIC_OPTIONS"] = INTERVENTION_SPECIFIC_OPTIONS

# 注册干预子配置
CONFIG_REGISTRY["ERXUE_YAWAN_CONFIG"] = ERXUE_YAWAN_CONFIG
CONFIG_REGISTRY["GUASHA_CONFIG"] = GUASHA_CONFIG
CONFIG_REGISTRY["AIGIU_CONFIG"] = AIGIU_CONFIG
CONFIG_REGISTRY["ZHONGYAO_XUNZHENG_CONFIG"] = ZHONGYAO_XUNZHENG_CONFIG
CONFIG_REGISTRY["REJIU_TRAINING_CONFIG"] = REJIU_TRAINING_CONFIG
CONFIG_REGISTRY["RECI_PULSE_CONFIG"] = RECI_PULSE_CONFIG
CONFIG_REGISTRY["BAOGUAN_CONFIG"] = BAOGUAN_CONFIG

# 注册选项配置
CONFIG_REGISTRY["INTERVENTION_TYPE_OPTIONS"] = INTERVENTION_TYPE_OPTIONS
CONFIG_REGISTRY["OPERATION_LOCATION_OPTIONS"] = OPERATION_LOCATION_OPTIONS
CONFIG_REGISTRY["PRESS_STRENGTH_OPTIONS"] = PRESS_STRENGTH_OPTIONS
CONFIG_REGISTRY["COOPERATION_LEVEL_OPTIONS"] = COOPERATION_LEVEL_OPTIONS
CONFIG_REGISTRY["IMMEDIATE_EFFECT_OPTIONS"] = IMMEDIATE_EFFECT_OPTIONS
CONFIG_REGISTRY["HOME_OPERATOR_RELATION_OPTIONS"] = HOME_OPERATOR_RELATION_OPTIONS
CONFIG_REGISTRY["PATIENT_REACTION_OPTIONS"] = PATIENT_REACTION_OPTIONS

# ==================== 全局唯一学生信息栏配置 ====================
# 所有模块统一使用此配置，确保学生信息显示的一致性
# 字段顺序：教育ID号、学校、年级/班级、姓名、性别、生日、身份证号码、家长姓名、家长电话
STUDENT_INFO_BAR_CONFIG = {
    "fields": [
        "education_id",     # 教育ID号
        "school",           # 学校
        "grade",            # 年级（当grade_class_combined=True时，会与班级合并显示）
        "name",             # 姓名
        "gender",           # 性别
        "birthday",         # 出生日期
        "id_card",          # 身份证号码
        "parent_name",      # 家长姓名
        "parent_phone"      # 家长电话
    ],
    "display_config": {
        "grade_class_combined": True,  # 年级和班级合并显示
        "show_empty_fields": False,    # 不显示空字段
        "field_order": "fixed"         # 固定字段顺序
    },
    "style_config": {
        "container_class": "student-info-bar-row",
        "item_class": "info-bar-item me-3 mb-1 d-inline-block",
        "label_style": "font-weight: bold;",
        "value_style": "color: #666;"
    }
}

# 注册全局唯一学生信息栏配置
CONFIG_REGISTRY["STUDENT_INFO_BAR_CONFIG"] = STUDENT_INFO_BAR_CONFIG

# ==================== 配置注册结束 ====================

# ==================== 组合查询配置开始 ====================

# 组合查询字段配置（全局唯一配置驱动）
# 🔧 重构：完全基于ALL_FIELD_CONFIG_REGISTRY，避免重复定义
# 注意：此配置由ConfigManager动态生成，这里只定义允许的字段列表
COMBO_QUERY_ALLOWED_FIELDS = {
    # 基础学生信息字段
    "students": [
        "education_id", "school", "class_name", "name", "gender"
    ],
    "student_extensions": [
        "data_year", "grade", "age"
    ],
    # 视力记录字段
    "vision_records": [
        "measurement_sequence", "measure_date", "measure_type",
        "vision_level", "left_eye_naked", "right_eye_naked",
        "left_sphere", "right_sphere", "left_cylinder", "right_cylinder",
        "left_axis", "right_axis", "left_se", "right_se",
        "age_at_measure"
    ],
    # 干预记录字段
    "intervention_records": [
        "intervention_type", "operator", "intervention_date"
    ],
    # 随访记录字段
    "followup_records": [
        "followup_date", "interviewer", "interviewee", "followup_type"
    ]
}

# 组合查询字段配置（由ConfigManager动态生成）
COMBO_QUERY_FIELD_CONFIG = {}

# 组合查询角色选项配置
COMBO_QUERY_ROLE_OPTIONS = [
    { "value": "metric", "label": "统计指标" },
    { "value": "group", "label": "分组" },
    { "value": "filter", "label": "筛选" }
]

# 组合查询模板配置
COMBO_QUERY_TEMPLATES = {
    "student_basic_info": {
        "name": "学生基本信息查询",
        "description": "查询学生基本档案信息",
        "fields": ["education_id", "school", "grade", "class_name", "name", "gender", "age"]
    },
    "vision_analysis": {
        "name": "视力分析查询",
        "description": "分析学生视力状况和变化",
        "fields": ["education_id", "name", "vision_level", "left_eye_naked", "right_eye_naked"]
    },
    "intervention_effect": {
        "name": "干预效果查询",
        "description": "分析干预措施的效果",
        "fields": ["education_id", "name", "intervention_type", "left_interv_effect", "right_interv_effect"]
    }
}

# 组合查询组件配置
COMBO_QUERY_COMPONENT_CONFIG = {
    "default_mode": "data_query",  # 'data_query' | 'report'
    "enable_roles": True,          # 是否启用角色选择
    "enable_templates": True,      # 是否启用模板查询
    "enable_column_config": True,  # 是否启用列配置
    "max_conditions": 10,          # 最大查询条件数量
    "auto_save": True,             # 是否自动保存查询条件
    "validation": {
        "required_fields": ["field", "operator"],
        "field_validation": True,
        "value_validation": True
    }
}

# 注册组合查询配置到全局配置表
CONFIG_REGISTRY["COMBO_QUERY_ALLOWED_FIELDS"] = COMBO_QUERY_ALLOWED_FIELDS
CONFIG_REGISTRY["COMBO_QUERY_FIELD_CONFIG"] = COMBO_QUERY_FIELD_CONFIG
CONFIG_REGISTRY["COMBO_QUERY_ROLE_OPTIONS"] = COMBO_QUERY_ROLE_OPTIONS
CONFIG_REGISTRY["COMBO_QUERY_TEMPLATES"] = COMBO_QUERY_TEMPLATES
CONFIG_REGISTRY["COMBO_QUERY_COMPONENT_CONFIG"] = COMBO_QUERY_COMPONENT_CONFIG

# ==================== 组合查询配置结束 ====================

# ==================== 查询模块默认列配置（全局唯一配置驱动） ====================

# 查询模块默认列配置（全局唯一配置驱动）
# 注意：此配置由ConfigManager动态生成，这里只定义基础配置
QUERY_DEFAULT_DISPLAY_COLUMNS = {
    "always_visible": ["education_id", "name"],
    "default_selected": ["school", "grade", "class_name", "gender", "age", "vision_level", "left_eye_naked", "right_eye_naked"],
    "available_columns": [],
    "column_groups": {},
    "field_display_mapping": {}
}

# 注册到全局配置表
CONFIG_REGISTRY["QUERY_DEFAULT_DISPLAY_COLUMNS"] = QUERY_DEFAULT_DISPLAY_COLUMNS

# ==================== 报表模块配置（全局唯一配置驱动） ====================

# 报表模板配置
REPORT_TEMPLATE_CONFIG = {
    "template1": {
        "name": "按年龄段",
        "description": "按年龄段分组统计学生视力状况",
        "group_field": "age",
        "group_type": "number_range",
        "group_ranges": [
            {"min": 6, "max": 9, "label": "6-9岁"},
            {"min": 10, "max": 12, "label": "10-12岁"},
            {"min": 13, "max": 15, "label": "13-15岁"},
            {"min": 16, "max": 18, "label": "16-18岁"}
        ],
        "default_metrics": ["vision_level", "intervention_type"],
        "display_name": "按年龄段统计"
    },
    "template2": {
        "name": "按性别",
        "description": "按性别分组统计学生视力状况",
        "group_field": "gender",
        "group_type": "multi-select",
        "group_options": ["男", "女"],
        "default_metrics": ["vision_level", "intervention_type"],
        "display_name": "按性别统计"
    },
    "template3": {
        "name": "按学校",
        "description": "按学校分组统计学生视力状况",
        "group_field": "school",
        "group_type": "multi-select",
        "group_options_source": "school_options",
        "default_metrics": ["vision_level", "intervention_type"],
        "display_name": "按学校统计"
    },
    "template4": {
        "name": "按年级",
        "description": "按年级分组统计学生视力状况",
        "group_field": "grade",
        "group_type": "multi-select",
        "group_options_source": "grade_options",
        "default_metrics": ["vision_level", "intervention_type"],
        "display_name": "按年级统计"
    }
}

# 报表字段映射配置已废弃 - 统一使用ALL_FIELD_CONFIG_REGISTRY中的display_name
# 删除原因：避免重复定义，统一字段显示名称管理

# 报表导出配置
REPORT_EXPORT_CONFIG = {
    "excel": {
        "enabled": True,
        "file_extension": ".xlsx",
        "mime_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        "default_filename": "统计报表_{timestamp}",
        "sheet_name": "统计报表",
        "header_style": {
            "font_bold": True,
            "alignment": "center",
            "background_color": "CCCCCC"
        },
        "data_style": {
            "alignment": "center",
            "number_format": "0.00"
        }
    },
    "pdf": {
        "enabled": False,
        "file_extension": ".pdf",
        "mime_type": "application/pdf"
    }
}

# 报表分页配置
REPORT_PAGINATION_CONFIG = {
    "default_per_page": 10,
    "per_page_options": [10, 20, 50, 100],
    "max_per_page": 1000,
    "show_total": True,
    "show_page_info": True
}

# 报表组件配置
REPORT_COMPONENT_CONFIG = {
    "enable_templates": True,
    "enable_custom_query": True,
    "enable_export": True,
    "enable_chart_view": True,
    "enable_pagination": True,
    "auto_refresh": False,
    "max_export_rows": 10000,
    "validation": {
        "require_group_field": True,
        "require_metric_field": True,
        "max_conditions": 20
    }
}

# 注册报表配置到全局配置表
CONFIG_REGISTRY["REPORT_TEMPLATE_CONFIG"] = REPORT_TEMPLATE_CONFIG
CONFIG_REGISTRY["REPORT_EXPORT_CONFIG"] = REPORT_EXPORT_CONFIG
CONFIG_REGISTRY["REPORT_PAGINATION_CONFIG"] = REPORT_PAGINATION_CONFIG
CONFIG_REGISTRY["REPORT_COMPONENT_CONFIG"] = REPORT_COMPONENT_CONFIG

# ==================== 报表模块配置结束 ====================

# ==================== 报表角色化字段配置（REPORT_ROLE_FIELD_CONFIG）====================
# 
# 📋 配置表调用关系说明：
# 
# 🔧 后端调用：
# - config_manager.py:get_report_role_field_config() - 获取完整配置
# - config_manager.py:get_report_metric_fields() - 获取统计指标字段
# - config_manager.py:get_report_group_fields() - 获取分组字段  
# - config_manager.py:get_report_filter_fields() - 获取筛选字段
# - config_manager.py:get_report_fields_by_role() - 根据角色获取字段
# - config_api.py:get_report_role_field_config() - API接口提供配置
# - config_api.py:get_report_fields_by_role() - API接口提供角色字段
# 
# 🔧 前端调用：
# - comboQuery_report.js:loadComboQueryConfig() - 加载组合查询配置
# - comboQuery_report.js:updateFieldOptions() - 更新字段选项
# - comboQuery_report.js:getRoleFieldsWithDisplayNames() - 获取角色字段
# 
# 🔧 共享模块：
# - analysis_api.py - 统计分析模块（复用统计指标字段）
# - report_api.py - 报表生成模块（复用分组和筛选字段）
# - chart_api.py - 图表生成模块（复用统计指标字段）
# 
# 📊 配置内容：
# - metric_fields: 统计指标字段（50+个字段，用于统计计算）
# - group_fields: 分组字段（30+个字段，用于数据分组）
# - filter_fields: 筛选字段（40+个字段，用于数据过滤）
# 
# ✅ 配置特点：
# - 完全引用ALL_FIELD_CONFIG_REGISTRY，避免重复定义
# - 通过table属性关联到具体数据表
# - 支持control_type指定控件类型
# - 提供description描述字段用途

# 报表角色化字段配置（完全引用全局唯一字段配置，不重复定义）
# 字段名称、显示名称、选项来源全部引用ALL_FIELD_CONFIG_REGISTRY和GLOBAL_OPTIONS_CONFIG
# 只保留description和role-specific配置，避免重复定义
REPORT_ROLE_FIELD_CONFIG = {
    # 统计指标字段配置（视力相关字段，用于统计计算）
    # 🔧 重新排列：按等级相关 → 效果相关 → 数值相关，每部分都左眼、右眼配对
    "metric_fields": {
        # ===== 等级相关字段（左眼、右眼配对） =====
        "comprehensive_vision_level": {
            "control_type": "multi-select",
            "table": "vision_records",
            "description": "综合视力等级统计"
        },
        "left_vision_level": {
            "control_type": "multi-select",
            "table": "vision_records",
            "description": "左眼视力等级统计"
        },
        "right_vision_level": {
            "control_type": "multi-select",
            "table": "vision_records",
            "description": "右眼视力等级统计"
        },
        
        # ===== 干预效果相关字段（左眼、右眼配对） =====
        "baseline_left_vision_effect": {
            "control_type": "multi-select",
            "table": "vision_records",
            "description": "左眼视力干预效果统计"
        },
        "baseline_right_vision_effect": {
            "control_type": "multi-select",
            "table": "vision_records",
            "description": "右眼视力干预效果统计"
        },
        "baseline_left_se_effect": {
            "control_type": "multi-select",
            "table": "vision_records",
            "description": "左眼SE干预效果统计"
        },
        "baseline_right_se_effect": {
            "control_type": "multi-select",
            "table": "vision_records",
            "description": "右眼SE干预效果统计"
        },
        
        # ===== 视力数值相关字段（左眼、右眼配对） =====
        "left_eye_naked": {
            "control_type": "number_range",
            "table": "vision_records",
            "description": "左眼裸眼视力数值统计"
        },
        "right_eye_naked": {
            "control_type": "number_range",
            "table": "vision_records",
            "description": "右眼裸眼视力数值统计"
        },
        "left_eye_corrected": {
            "control_type": "number_range",
            "table": "vision_records",
            "description": "左眼矫正视力数值统计"
        },
        "right_eye_corrected": {
            "control_type": "number_range",
            "table": "vision_records",
            "description": "右眼矫正视力数值统计"
        },
        
        # ===== 屈光度相关字段（左眼、右眼配对） =====
        "left_sphere": {
            "control_type": "number_range",
            "table": "vision_records",
            "description": "左眼球镜数值统计"
        },
        "right_sphere": {
            "control_type": "number_range",
            "table": "vision_records",
            "description": "右眼球镜数值统计"
        },
        "left_cylinder": {
            "control_type": "number_range",
            "table": "vision_records",
            "description": "左眼柱镜数值统计"
        },
        "right_cylinder": {
            "control_type": "number_range",
            "table": "vision_records",
            "description": "右眼柱镜数值统计"
        },
        "left_se": {
            "control_type": "number_range",
            "table": "vision_records",
            "description": "左眼SE数值统计"
        },
        "right_se": {
            "control_type": "number_range",
            "table": "vision_records",
            "description": "右眼SE数值统计"
        },
        
        # ===== 测量管理相关字段 =====
        "measurement_sequence": {
            "control_type": "number_input",
            "table": "vision_records",
            "description": "测量序号统计"
        },
        "age_at_measure": {
            "control_type": "number_range",
            "table": "vision_records",
            "description": "测量时年龄统计"
        }
    },
    
    # 分组字段配置（基本信息、扩展信息、干预信息字段，用于数据分组）
    # 🔧 重新排列：按基本信息 → 扩展信息 → 干预信息的逻辑顺序
    "group_fields": {
        # ===== 基本信息字段（按重要性排序） =====
        "gender": {
            "control_type": "multi-select",
            "table": "students",
            "description": "按性别分组"
        },
        "school": {
            "control_type": "multi-select",
            "table": "students",
            "description": "按学校分组"
        },
        "class_name": {
            "control_type": "multi-select",
            "table": "students",
            "description": "按班级分组"
        },
        "region": {
            "control_type": "text",
            "table": "students",
            "description": "按区域分组"
        },
        
        # ===== 扩展信息字段（按使用频率排序） =====
        "grade": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按年级分组"
        },
        "age": {
            "control_type": "number_range",
            "table": "student_extensions",
            "description": "按年龄分组"
        },
        "data_year": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按数据年份分组"
        },
        "premature": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按早产情况分组"
        },
        "diet_preference": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按饮食偏好分组"
        },
        "exercise_preference": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按运动偏好分组"
        },
        
        # ===== 矫正方式相关字段（按使用频率排序） =====
        "correction_method": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按矫正方式分组"
        },
        
        # ===== 干预信息字段（按操作流程排序） =====
        "intervention_type": {
            "control_type": "multi-select",
            "table": "intervention_records",
            "description": "按干预方式分组"
        },
        "operation_location": {
            "control_type": "multi-select",
            "table": "intervention_records",
            "description": "按操作部位分组"
        },
        "operator": {
            "control_type": "text",
            "table": "intervention_records",
            "description": "按操作人员分组"
        },
        
        # ===== 视力记录字段（按测量管理排序） =====
        "measurement_sequence": {
            "control_type": "number_input",
            "table": "vision_records",
            "description": "按测量序号分组"
        },
        "measure_date": {
            "control_type": "date",
            "table": "vision_records",
            "description": "按测量日期分组"
        },
        "measure_type": {
            "control_type": "multi-select",
            "table": "vision_records",
            "description": "按测量类型分组"
        }
    },
    
    # 筛选字段配置（基本信息和扩展信息字段，用于数据过滤）
    # 🔧 重新排列：按基本信息 → 扩展信息的逻辑顺序，符合用户查询习惯
    "filter_fields": {
        # ===== 基本信息字段（按查询频率排序） =====
        "education_id": {
            "control_type": "text",
            "table": "students",
            "description": "按教育ID筛选"
        },
        "name": {
            "control_type": "text",
            "table": "students",
            "description": "按姓名筛选"
        },
        "gender": {
            "control_type": "multi-select",
            "table": "students",
            "description": "按性别筛选"
        },
        "school": {
            "control_type": "multi-select",
            "table": "students",
            "description": "按学校筛选"
        },
        "class_name": {
            "control_type": "multi-select",
            "table": "students",
            "description": "按班级筛选"
        },
        "id_card": {
            "control_type": "text",
            "table": "students",
            "description": "按身份证号筛选"
        },
        "region": {
            "control_type": "text",
            "table": "students",
            "description": "按区域筛选"
        },
        
        # ===== 扩展信息字段（按查询频率排序） =====
        "grade": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按年级筛选"
        },
        "age": {
            "control_type": "number_range",
            "table": "student_extensions",
            "description": "按年龄筛选"
        },
        "data_year": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按数据年份筛选"
        },
        "premature": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按早产情况筛选"
        },
        "diet_preference": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按饮食偏好筛选"
        },
        "exercise_preference": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按运动偏好筛选"
        },
        "correction_method": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按矫正方式筛选"
        },
        "frame_glasses": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按框架眼镜使用情况筛选"
        },
        "contact_lenses": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按隐形眼镜使用情况筛选"
        },
        "night_orthokeratology": {
            "control_type": "multi-select",
            "table": "student_extensions",
            "description": "按夜戴角膜塑形镜使用情况筛选"
        },
        "past_history": {
            "control_type": "text",
            "table": "student_extensions",
            "description": "按既往史筛选"
        },
        "family_history": {
            "control_type": "text",
            "table": "student_extensions",
            "description": "按家族史筛选"
        },
        "allergy": {
            "control_type": "text",
            "table": "student_extensions",
            "description": "按过敏史筛选"
        },
        
        # ===== 视力记录字段（按测量管理排序） =====
        "measurement_sequence": {
            "control_type": "number_input",
            "table": "vision_records",
            "description": "按测量序号筛选（第几次检查）"
        },
        "measure_date": {
            "control_type": "date",
            "table": "vision_records",
            "description": "按测量日期筛选"
        },
        "measure_type": {
            "control_type": "multi-select",
            "table": "vision_records",
            "description": "按测量类型筛选"
        }
    }
}

# 注册报表角色化字段配置到全局配置表
CONFIG_REGISTRY["REPORT_ROLE_FIELD_CONFIG"] = REPORT_ROLE_FIELD_CONFIG

# ==================== 固定查询指标配置（FIXED_METRICS）====================
# 
# 📋 配置表调用关系说明：
# 
# 🔧 后端调用：
# - config_manager.py:get_config("FIXED_METRICS") - 获取固定查询指标
# - config_api.py:get_analysis_fixed_metrics() - API接口提供配置
# - analysis_api.py - 统计分析模块（固定模板使用）
# - chart_api.py - 图表生成模块（固定模板使用）
# 
# 📊 配置特点：
# - 基于ALL_FIELD_CONFIG_REGISTRY，不重复定义字段
# - 只定义字段名称列表，字段配置统一管理
# - 用于聚合分析模块的固定模板模式

# 固定查询指标配置（基于全局字段配置，不重复定义）
FIXED_METRICS = [
    "education_id", "name", "school", "grade", "class_name", "gender", "age", 
    "left_eye_naked", "right_eye_naked", "vision_level"
]

# 注册固定查询指标配置
CONFIG_REGISTRY["FIXED_METRICS"] = FIXED_METRICS

# ==================== 权限-功能映射配置（全局唯一） ====================
# 标准化模块级+操作级权限-功能配置表，所有权限校验、前端动态获取均以此为唯一来源
PERMISSION_FEATURE_MAP = {
    "user": {
        "display_name": "用户管理",
        "features": {
            "view": {"display_name": "查看用户", "permission_code": "user:view", "description": "查看用户列表和详情"},
            "create": {"display_name": "创建用户", "permission_code": "user:create", "description": "新增用户"},
            "edit": {"display_name": "编辑用户", "permission_code": "user:edit", "description": "编辑用户信息"},
            "delete": {"display_name": "删除用户", "permission_code": "user:delete", "description": "删除用户"},
            "assign_role": {"display_name": "分配角色", "permission_code": "user:assign_role", "description": "为用户分配角色"},
            "import": {"display_name": "导入用户", "permission_code": "user:import", "description": "批量导入用户"},
            "export": {"display_name": "导出用户", "permission_code": "user:export", "description": "导出用户数据"}
        }
    },
    "role": {
        "display_name": "角色管理",
        "features": {
            "view": {"display_name": "查看角色", "permission_code": "role:view", "description": "查看角色列表和详情"},
            "create": {"display_name": "创建角色", "permission_code": "role:create", "description": "新增角色"},
            "edit": {"display_name": "编辑角色", "permission_code": "role:edit", "description": "编辑角色信息"},
            "delete": {"display_name": "删除角色", "permission_code": "role:delete", "description": "删除角色"},
            "assign_permission": {"display_name": "分配权限", "permission_code": "role:assign_permission", "description": "为角色分配权限"}
        }
    },
    "permission": {
        "display_name": "权限管理",
        "features": {
            "view": {"display_name": "查看权限", "permission_code": "permission:view", "description": "查看权限列表和详情"},
            "create": {"display_name": "创建权限", "permission_code": "permission:create", "description": "新增权限"},
            "edit": {"display_name": "编辑权限", "permission_code": "permission:edit", "description": "编辑权限信息"},
            "delete": {"display_name": "删除权限", "permission_code": "permission:delete", "description": "删除权限"}
        }
    },
    "student": {
        "display_name": "学生档案管理",
        "features": {
            "view": {"display_name": "查看学生", "permission_code": "student:view", "description": "查看学生档案"},
            "create": {"display_name": "创建学生", "permission_code": "student:create", "description": "新增学生档案"},
            "edit": {"display_name": "编辑学生", "permission_code": "student:edit", "description": "编辑学生档案"},
            "delete": {"display_name": "删除学生", "permission_code": "student:delete", "description": "删除学生档案"},
            "import": {"display_name": "导入学生", "permission_code": "student:import", "description": "批量导入学生"},
            "export": {"display_name": "导出学生", "permission_code": "student:export", "description": "导出学生数据"},
            "log": {"display_name": "操作日志", "permission_code": "student:log", "description": "查看学生档案操作日志"}
        }
    },
    "vision": {
        "display_name": "视力管理",
        "features": {
            "view": {"display_name": "查看视力", "permission_code": "vision:view", "description": "查看视力记录"},
            "create": {"display_name": "创建视力", "permission_code": "vision:create", "description": "新增视力记录"},
            "edit": {"display_name": "编辑视力", "permission_code": "vision:edit", "description": "编辑视力记录"},
            "delete": {"display_name": "删除视力", "permission_code": "vision:delete", "description": "删除视力记录"},
            "export": {"display_name": "导出视力", "permission_code": "vision:export", "description": "导出视力数据"},
            "log": {"display_name": "操作日志", "permission_code": "vision:log", "description": "查看视力操作日志"}
        }
    },
    "intervention": {
        "display_name": "干预管理",
        "features": {
            "view": {"display_name": "查看干预", "permission_code": "intervention:view", "description": "查看干预记录"},
            "create": {"display_name": "创建干预", "permission_code": "intervention:create", "description": "新增干预记录"},
            "edit": {"display_name": "编辑干预", "permission_code": "intervention:edit", "description": "编辑干预记录"},
            "delete": {"display_name": "删除干预", "permission_code": "intervention:delete", "description": "删除干预记录"},
            "export": {"display_name": "导出干预", "permission_code": "intervention:export", "description": "导出干预数据"},
            "log": {"display_name": "操作日志", "permission_code": "intervention:log", "description": "查看干预操作日志"}
        }
    },
    "followup": {
        "display_name": "随访管理",
        "features": {
            "view": {"display_name": "查看随访", "permission_code": "followup:view", "description": "查看随访记录"},
            "create": {"display_name": "创建随访", "permission_code": "followup:create", "description": "新增随访记录"},
            "edit": {"display_name": "编辑随访", "permission_code": "followup:edit", "description": "编辑随访记录"},
            "delete": {"display_name": "删除随访", "permission_code": "followup:delete", "description": "删除随访记录"},
            "export": {"display_name": "导出随访", "permission_code": "followup:export", "description": "导出随访数据"},
            "log": {"display_name": "操作日志", "permission_code": "followup:log", "description": "查看随访操作日志"}
        }
    },
    "report": {
        "display_name": "报表管理",
        "features": {
            "view": {"display_name": "查看报表", "permission_code": "report:view", "description": "查看统计报表"},
            "export": {"display_name": "导出报表", "permission_code": "report:export", "description": "导出统计报表"}
        }
    },
    "chart": {
        "display_name": "图表展示",
        "features": {
            "view": {"display_name": "查看图表", "permission_code": "chart:view", "description": "查看统计图表"},
            "export": {"display_name": "导出图表", "permission_code": "chart:export", "description": "导出图表数据"}
        }
    },
    "query": {
        "display_name": "查询管理",
        "features": {
            "view": {"display_name": "执行查询", "permission_code": "query:view", "description": "执行数据查询"},
            "export": {"display_name": "导出查询结果", "permission_code": "query:export", "description": "导出查询结果"}
        }
    },
    "data_import": {
        "display_name": "数据导入",
        "features": {
            "import": {"display_name": "导入数据", "permission_code": "data_import:import", "description": "批量导入数据"}
        }
    },
    "operation_log": {
        "display_name": "操作日志",
        "features": {
            "view": {"display_name": "查看日志", "permission_code": "operation_log:view", "description": "查看系统操作日志"},
            "export": {"display_name": "导出日志", "permission_code": "operation_log:export", "description": "导出操作日志"}
        }
    },
    "sidebar": {
        "display_name": "侧边栏管理",
        "features": {
            "view": {"display_name": "查看侧边栏", "permission_code": "sidebar:view", "description": "查看侧边栏菜单"},
            "edit": {"display_name": "编辑侧边栏", "permission_code": "sidebar:edit", "description": "编辑侧边栏菜单"}
        }
    }
    # 可继续扩展其他模块
}

# 注册到配置项注册表，便于ConfigManager统一访问
CONFIG_REGISTRY["PERMISSION_FEATURE_MAP"] = PERMISSION_FEATURE_MAP
